javascript - Display select fields using conditional statements in JS -


i designing self-service site people problems accessing secure website. want generate drop downs questions situation based on answers each previous drop down box. trying use js , conditional statements accomplish this. not programmer understand enough reverse engineer it. here's have far.

<select id="location" name="location" onclick='test()'>   <option value="0">is personal computer or government computer?</option>   <option value="home">personal</option>   <option value="gfe">government</option> </select>  <select id="home" name="home" style="display: none" onclick='test()'>   <option value="0">do have cac?</option>   <option value="1">yes</option>   <option value="2">no</option> </select>  <select id="multi-cac" name="multi-cac" style="display: none" onclick='test()'>   <option value="0">how many cacs have?</option>   <option value="1">1</option>   <option value="2">more 1</option> </select>  <select id="gfe" name="gfe" style="display: none" onclick='test()'>   <option value="0">is shared computer?</option>   <option value="1">yes</option>   <option value="2">no</option> </select>  <select id="shared" name="shared" style="display: none" onclick='test()'>   <option value="0">can other people access owa on it?</option>   <option value="1">yes</option>   <option value="2">no</option> </select>  <select id="overseas" name="overseas" style="display: none" onclick='test()'>   <option value="0">have returned overseas deployment?</option>   <option value="1">yes</option>   <option value="2">no</option> </select>  <div id="overseas-answer" style="display: none" onclick='test()'>   please visit <a href="https://www.dmdc.osd.mil/milconnect">milconnect</a> , update profile. please wait 24 hours , try accessing email again. if not work, please contact desk   </div>      function test() {   if (document.getelementbyid('location').value == 'home') {     document.getelementbyid('home').style.display = 'block';   } else {     document.getelementbyid('home').style.display = 'none';   }    if (document.getelementbyid('location').value == 'gfe') {     document.getelementbyid('gfe').style.display = 'block';   } else {     document.getelementbyid('gfe').style.display = 'none';   }    if (document.getelementbyid('gfe').value == '1') {     document.getelementbyid('shared').style.display = 'block';   }  else {     document.getelementbyid('shared').style.display = 'none';   }    if (document.getelementbyid('shared').value == '1') {     document.getelementbyid('overseas').style.display = 'block';   } else {     document.getelementbyid('overseas').style.display = 'none';   }    if (document.getelementbyid('overseas').value == '1') {     document.getelementbyid('overseas-answer').style.display = 'block';   } else {     document.getelementbyid('overseas-answer').style.display = 'none';   } } 

where i'm getting stuck can't figure out how write code "if value gfe 1 show shared. if value of gfe 2 show multicac." when try write either not work or shows drop downs don't want user see yet.

http://jsfiddle.net/jkqwf/341/ here link it.

am going @ wrong? there easier way this?

thanks in advance.

the issue have way have is... when test called goes down , hits every if , tries value each drop down displaying or not. want worry select changed.

for each of selects this...

<select id="location" name="location" onchange='test(this.id, this.value)'>

then test...

function test(id, val){   if(id == "location"){     handlelocationvalues(val);   }   else if(id == "home"){     handlehomevalues(val);   }   ...   ... } 

then can make "handle values" functions this...

function handlelocationvalue(val){   if(val == "home"){     // write code show home drop down..   }   else if{val == "gfe"){     // write code show gfe drop down...   }   ... } 

you going want write logic if user goes , changes 1 of previous select hide of visible selects below it.

i noticed in fiddle have jquery selected 1 of frameworks. if pulling in suggest looking using make easier. not use inline events , styles.

i hope helps , luck.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -