Possible Duplicate:
Check of specific radio button is checked
I have these 2 radio buttons at the moment so that the user can decide whether they need postage included in the price or not:
<input type="radio" id="postageyes" name="postage" value="Yes" /> Yes
<input type="radio" id="postageno" name="postage" value="No" /> No
I need to use Jquery to check if the 'yes' radio button is checked, and if it is, do an append function. Could someone tell me how I'd do this please?
Thanks for any help
edit:
I've updated my code to this, but it's not working. Am I doing something wrong?
<script type='text/javascript'>
// <![CDATA[
jQuery(document).ready(function(){
$('input:radio[name="postage"]').change(function(){
if($(this).val() == 'Yes'){
alert("test");
}
});
});
// ]]>
</script>
This question is related to
jquery
html
radio-button
$('input:radio[name="postage"]').change(function(){
if($(this).val() === 'Yes'){
// append stuff
}
});
This will listen for a change event on the radio buttons. At the time the user clicks Yes
, the event will fire and you will be able to append anything you like to the DOM.
$("input").bind('click', function(e){
if ($(this).val() == 'Yes') {
$("body").append('whatever');
}
});
Try this:
if ( jQuery('#postageyes').is(':checked') ){ ... }
This will listen to the changed event. I have tried the answers from others but those did not work for me and finally, this one worked.
$('input:radio[name="postage"]').change(function(){
if($(this).is(":checked")){
alert("lksdahflk");
}
});
Try this
if($("input:radio[name=postage]").is(":checked")){
//Code to append goes here
}
Something like this:
if($('#postageyes').is(':checked')) {
// do stuff
}
jQuery('input[name="inputName"]:checked').val()
if($('#test2').is(':checked')) {
$(this).append('stuff');
}
Source: Stackoverflow.com