Hi HermanBos,
I have a similar problem using BunnyBomb's solution but with some customization according my needs.
I have to make a form with a dropdown field such as this:
--- (blank)
One kid
Two kids
Three kids
And than, if someone select "One kid", form will show up just one text field to be filed with kids age.
If someone select "Two kids", form will show up two text fields so the user can input ages for both kids separately.
If someone select "Three kids", form will show up three text fields so user can also input their ages separately (and so on if needed).
Now, my code looks like this:
/*! jQuery script to hide certain form fields */
$(document).ready(function() {
//Hide the field initially
$("#onekid").hide();
$("#twokids").hide();
$("#threekids").hide();
$('#awesome').change(function() {
if ($("#awesome").val() == "1") {
$("#onekid").show();
$("#twokids").hide();
$("#threekids").hide();
}
});
$('#awesome').change(function() {
if ($("#awesome").val() == "2") {
$("#onekid").show();
$("#twokids").show();
$("#threekids").hide();
}
});
$('#awesome').change(function() {
if ($("#awesome").val() == "3") {
$("#onekid").show();
$("#twokids").show();
$("#threekids").show();
}
});
});
and it works except when I click some option from dropdown (eg. Three kids), and than click blank again, it wont clear empty fields!
I've tried about a 50 different solutions but none with a complete success.
Any ideas? Thanks...