To keep it simple I have 2 form multiple select elements. Depending on the dropdown selected, it will auto hide or show additional input fields.
This is achieved like such:
$(document).ready(function(){
$("#find-replace1 select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="Find/Replace"){
$(".rep1").hide();
$(".find1").show();
$(".replace1").show();
} else {
$(".rep1").show();
$(".find1").hide();
$(".replace1").hide();
}
});
}).change();
});
$(document).ready(function(){
$("#find-replace2 select").change(function(){
$( "select option:selected").each(function(){
if($(this).attr("value")=="Find/Replace"){
$(".rep2").hide();
$(".find2").show();
$(".replace2").show();
} else {
$(".rep2").show();
$(".find2").hide();
$(".replace2").hide();
}
});
}).change();
});
My html is:
<p>
<form method="POST" action="#" accept-charset="UTF-8">
<div id="find-replace1" class="form-group-a">
<select class="form-control" name="priceaction">
<option value="Append">Append</option>
<option value="Prepend">Prepend</option>
<option value="Replace">Replace</option>
<option value="Find/Replace">Find/Replace</option>
</select>
</div>
<div class="form-group-a">
<input class="form-control formwidth rep1" autocomplete="off" name="value" type="text" style="display: block;">
</div>
<div class="form-group-a">
<input class="form-control formwidth find1" autocomplete="off" placeholder="find this" name="find" type="text" style="display: none;">
</div>
<div class="form-group-a">
<input class="form-control formwidth replace1" autocomplete="off" placeholder="replace with" name="replace" type="text" style="display: none;">
</div>
<div class="clear"></div>
<input type="submit" value="Update">
</form>
</p>
<hr>
<p>
<form method="POST" action="#" accept-charset="UTF-8">
<div id="find-replace2" class="form-group-a">
<select class="form-control" name="priceaction">
<option value="Append">Append</option>
<option value="Prepend">Prepend</option>
<option value="Replace">Replace</option>
<option value="Find/Replace">Find/Replace</option>
</select>
</div>
<div class="form-group-a">
<input class="form-control formwidth rep2" autocomplete="off" name="value" type="text" style="display: block;">
</div>
<div class="form-group-a">
<input class="form-control formwidth find2" autocomplete="off" placeholder="find this" name="find" type="text" style="display: none;">
</div>
<div class="form-group-a">
<input class="form-control formwidth replace2" autocomplete="off" placeholder="replace with" name="replace" type="text" style="display: none;">
</div>
<div class="clear"></div>
<input type="submit" value="Update">
</form>
</p>
Here is the jsfiddle: https://jsfiddle.net/kqjkprc1/
On my live site I actually have more than one form element but I kept it simple with 2 for this example. I notice it only applies the jQuery to the last form element on the page no matter what. Not sure why the first form element is unaffected and won't show/hide the hidden input fields.