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);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label><input type="radio" name="am_payment" value="3"> <strong>64</strong></label>
<label><input type="radio" name="am_payment" value="11"> <strong>100</strong></label>
<label><input type="radio" name="am_payment" value="32"> <strong>250</strong></label>
<label><input type="radio" value="" name="am_payment" checked>Other</label>
<input type="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
function activate() {
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('');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="radio" name="am_payment" value="3" checked="checked"> <strong>64</strong>
<input type="radio" name="am_payment" value="11" checked="checked"> <strong>100</strong>
<input type="radio" name="am_payment" value="32" checked="checked"> <strong>250</strong>
<input type="radio" value="" name="am_payment" id="other">
<label>Other</label>
<span onclick="activate();"><input type="text" name="CP_otheramount" value="" id="theamount" disabled="disabled"/></span>
Post a Comment for "Clearing A Textbox When Any Other Radio Buttons Are Selected"