In my form I need to show/hide multiple divs depending on which OPTION in a SELECT was chosen.
I can get in running but my problem is, that one div can get hidden/shown by many OPTIONS. So with my code these divs show/hide for a certain time and hide/show again then.
Here is my HTML:
<select id="vFormat" name="vFormat" onchange="getval(this);">
<option value="0">Choose</option>
<option value="1" class="format1">Option 1</option>
<option value="2" class="format2">Option 2</option>
<option value="3" class="format3">Option 2</option>
<option value="4" class="format4">Option 2</option>
<option value="5" class="format5">Option 2</option>
</select>
<div class="showdivformat1 showdivformat2 hiddenelement">
Text of hidden Div
</div>
<div class="hidedivformat2 showdivformat5 visibleelement">
Text of visible Div
</div>
Here is my jQuery
function getval(sel) {
var divval = $('.selectInput option:selected').attr('class').split(' ');
for(var i=0; i<divval.length; i++){
$(".hiddenelement").hide("50");
$(".showdiv" + divval[i]).show("50");
}
for(var i=0; i<divval.length; i++){
$(".visibleelement").show("50");
$(".hidediv" + divval[i]).hide("50");
}
}
I know the problem is, that I always hide the .hiddenelement and show the .visibleelement when changing the option.
But I don`t have a solution to check if a div is already hidden oder visible and should stay like this after the option change.