javascript - How to show a hidden div if multiple conditions apply to it? -


i've hit bit of snag in program working on. after asking last question had able complete entire thing until point. i'm attempting instead of having create multiple div's code work(it work way rather cut down on amount of code) using 1 div show show. example, here jfiddle example of i'm attempting do.

http://jsfiddle.net/vcq9l/

this example of html i'm using

<input name="search_fields" type="radio" onclick="showtest(0)" /> test  <div id="test0"> test 0<p></p> <input name="search_fields" type="radio" onclick="showtest(1)" />test 1 <input name="search_fields" type="radio" onclick="showtest(2)" />test 2 <input name="search_fields" type="radio" onclick="showtest(3)" />test 3 <p></p> </div>  <div id="test1"> test 1<p></p> <input name="search_fields" type="radio" onclick="showtest(4)" />one <input name="search_fields" type="radio" onclick="showtest(4)" />two <p></p> </div>  <div id="test2"> test 2<p></p> <input name="search_fields" type="radio" onclick="showtest(4)" />one <input name="search_fields" type="radio" onclick="showtest(4)" />two <p></p> </div>  <div id="test3"> test 3<p></p> <input name="search_fields" type="radio" onclick="showtest(4)" />one <input name="search_fields" type="radio" onclick="showtest(4)" />two <p></p> </div>  <div id="test4">     test </div> 

and here js

function showtest(test){     $('[id^="test"]').hide();     if(test >= 0){         $('#test0').show();          }     if(test === 4){         $('#test1').show();         $('#test2').hide();         $('#test3').hide();     }     $('#test' + test).show('slow'); } 

when run jfiddle how first radio button runs down line , displays final test div how of them if makes sense. best put data array , call on array in js displays how or simpler that?


Comments