I have two radio button
on change event i want change button How it is possible?
My Code
<input type="radio" name="bedStatus" id="allot" checked="checked" value="allot">Allot
<input type="radio" name="bedStatus" id="transfer" value="transfer">Transfer
Script
<script>
$(document).ready(function () {
$('input:radio[name=bedStatus]:checked').change(function () {
if ($("input[name='bedStatus']:checked").val() == 'allot') {
alert("Allot Thai Gayo Bhai");
}
if ($("input[name='bedStatus']:checked").val() == 'transfer') {
alert("Transfer Thai Gayo");
}
});
});
</script>
You can use
thiswhich refers to the currentinputelement.http://jsfiddle.net/4gZAT/
Note that you are comparing the value against
allotin both if statements and:radioselector is deprecated.In case that you are not using jQuery, you can use the
document.querySelectorAllandHTMLElement.addEventListenermethods: