HTML:
<div id="chips">
<label>
<input type="radio" name="pet_chipped" class="chipped" value="Yes" id="chipyes" checked> Yes</label>
<label>
<input type="radio" name="pet_chipped" class="chipped" value="No" id="chipno"> No</label>
</div>
jQuery:
$("input[name='pet_chipped']:checked").val();
when I am alerting 'pet_chipped' it displaying undefined.
//onload event
$(document).ready(function(){
/*show alert on load time*/
alert($('[name="pet_chipped"]:checked').val());
})
// on change radio button value fire event
$(document).on('change', '[name="pet_chipped"]', function(){
//show value of radio after changed
alert($('[name="pet_chipped"]:checked').val());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="chips">
<label> <input type="radio" name="pet_chipped" class="chipped" value="Yes" id="chipyes" checked> Yes</label>
<label><input type="radio" name="pet_chipped" class="chipped" value="No" id="chipno"> No</label>
</div>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments