Issue
I have a problem in my code, I wanna show input text form when I click one of radio button. Ajax code :
<script type="text/javascript">
$(document).ready(function(){
$('#macam').click( function() {
var value = $(this).val();
if(value == "0"){
$("#hilang").html("<input name='' value='tes' type='text' />");
}
else{
$("#hilang").html("");
}
});
});
</script>
HTML code :
<input id="macam" type="radio" name="radio" value="1" checked></input>
<input id="macam" type="radio" name="radio" value="0"></input>
<div id="hilang"></div>
Solution
Don't reuse ids
JS
$(document).ready(function(){
$('input[name="radio"]').click( function() {
var value = $(this).val();
if(value == "0"){
$("#hilang").html("<input name='' value='tes' type='text' />");
}
else{
$("#hilang").html("");
}
});
});
HTML
<input id="macam1" type="radio" name="radio" value="1" checked></input>
<input id="macam0" type="radio" name="radio" value="0"></input>
<div id="hilang"></div>
Answered By - chiliNUT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.