简体   繁体   中英

Drop down value should change according Radio Button

I need drop down select value will change dynamically according to two radio button. For example here in my html code , if select country 1 from country and select city1 from city then drop down value will be set 1 and if select country 1 from country and select city2 from city then drop down value will be set 2. I need JavaScript or php code.

Thanks for any help.

<div class='aQuestion' id='div1'>
    <STRONG>1. </STRONG>
    <STRONG>Country</STRONG></br>
    <INPUT TYPE='radio' NAME='grp1' VALUE='Country 0'>Country1</br>



</div>

<div class='aQuestion' id='div2'>
    <STRONG>2. </STRONG>
    <STRONG>City</STRONG></br>
    <INPUT TYPE='radio' NAME='grp2' VALUE='City 0'>City 1</br>
    <INPUT TYPE='radio' NAME='grp2' VALUE='City1'>City 2</br>


</div><br/>

<div> set 1 
<select name="school">

<option value="school1">school 1</option>;
<option value="school2">school 2</option>;
<option value="school3">school 3</option>;


</select><br/>
</div><br/>


<div>
 set 2
<select name="school">

<option value="school4">school 4</option>;
<option value="school5">school 5</option>;
<option value="school6">school 6</option>;

</select>
</div>

Replace

<INPUT TYPE='radio' NAME='grp2' VALUE='City 0'>City 1</br>
<INPUT TYPE='radio' NAME='grp2' VALUE='City1'>City 2</br>

with

 <INPUT TYPE='radio' NAME='grp2' VALUE='City 0' onClick="javascript:return yourfunction(1)">City 1</br>
 <INPUT TYPE='radio' NAME='grp2' VALUE='City1' onClick="javascript:return yourfunction(2)">City 2</br>


JavaScript code

function yourfunction(radioid)
{
  if(radioid == 1)
  {    
document.getElementById('one').style.display = '';
    document.getElementById('two').style.display = 'none';
  }
  else if(radioid == 2)
  {  
   document.getElementById('two').style.display = '';
   document.getElementById('one').style.display = 'none';
  }
}

Working Model, Refer this

http://jsfiddle.net/NWWL4/23/

hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM