Clearing A Textbox When Any Other Radio Buttons Are Selected
I started working on some code for a webpage yesterday & i am having trouble getting a few things working. I have 4 radio buttons, 3 of which have values applied to them &
Solution 1:
About this?
$('input[name="am_payment"]').on('click', function() {
if ($(this).val() === '') {
$('#theamount').val('').prop("disabled", false).focus();
}
else {
$('#theamount').val('').prop("disabled", true);
}
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><label><inputtype="radio"name="am_payment"value="3"><strong>64</strong></label><label><inputtype="radio"name="am_payment"value="11"><strong>100</strong></label><label><inputtype="radio"name="am_payment"value="32"><strong>250</strong></label><label><inputtype="radio"value=""name="am_payment"checked>Other</label><inputtype="number"name="CP_otheramount"value=""id="theamount" />
Solution 2:
I guess what you want is that when someone click on the text input the radio event has to be triggered and the input has to be on focus
functionactivate() {
console.log('clicked');
$('#other').prop('checked', true);
$('#other').trigger('click');
$('#theamount').focus();
}
$('input[name="am_payment"]').on('click', function() {
console.log('changed');
if ($(this).val() === '') {
$('input[name="CP_otheramount"]').val('');
$('#theamount').removeAttr("disabled");
} else {
$('#theamount').prop("disabled", "disabled");
$('input[name="CP_otheramount"]').val('');
}
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><inputtype="radio"name="am_payment"value="3"checked="checked"><strong>64</strong><inputtype="radio"name="am_payment"value="11"checked="checked"><strong>100</strong><inputtype="radio"name="am_payment"value="32"checked="checked"><strong>250</strong><inputtype="radio"value=""name="am_payment"id="other"><label>Other</label><spanonclick="activate();"><inputtype="text"name="CP_otheramount"value=""id="theamount"disabled="disabled"/></span>
Post a Comment for "Clearing A Textbox When Any Other Radio Buttons Are Selected"