I want to create 3 textfield which depend on radio button. When user click specific value of radio button , textfield appear depend on user choose and viceverse.
$(document).ready(function() {
$("input:radio[name='article']").change(function() {
if (this.value == '1' && this.checked) {
$("#nmb").show();
}
else if(this.value == '2' && this.checked) {
$("#nbc").show();
}
else if(this.value == '3' && this.checked) {
$("#crdb").show();
} else {
$("#crdb").hide();
$("#nmb").hide();
$("#nbc").hide();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<input type="radio" name="article" value="1"> NMB Bank <input type="radio" name="article" value="2">NBC Bank <input type="radio" name="article" value="3"> CRDB Bank <br/><br/>
<div id="nmb">Account Number: <input type="text" name="number" maxlength="11"><br><br> </div>
<div id="nbc">Account Number: <input type="text" name="number" maxlength="13"><br><br> </div>
<div id="crdb">Account Number: <input type="text" name="number" maxlength="14"><br><br> </div>
2
Answers
First you need to add a class to all div for example
account_number
:then you need to hide this divs :
and when a radio button is checked you hide all divs and show the corresponding textfield :
https://jsfiddle.net/b8pdao6L/1/
Is this what you looking for?
Note there is no reason to use
this.checked
.Demo