I have the following and in this order:
<script type="text/javascript">
$(document).ready(function(){
var overwrite = $('#itemList input:radio:checked').val()
alert('value = '+ overwrite);
});
</script>
<body>
<form ..... >
<div id="itemList">
Overwrite?
<input type="radio" value="Yes" class="overWrite" name="overWrite" >Yes
<input type="radio" value="No" class="overWrite" name="overWrite" >No
</div>
</form>
</body>
when it runs, the alert will have 'value = undefined'
BUT, if I put the javascript after the div (or body), the alert comes back with 'value = Yes'
Why does jquery not recognize the type radio at beginning of page? If I create a type = 'hidden', jquery can read/recognize the value if at beginning of page. When type = 'radio', behaviour is different
I had similar problem with 'undefined'.
when I tested this
var isChecked = $('#itemList').attr('checked');
isChecked was 'undefined'
and for this
var isChecked = $('#itemList').prop('checked');
isChecked is true or false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With