Jump to content

dependent drop down list


ilikephp

Recommended Posts

Hi,

 

I have this code below, it is working fine, but I need to put it 3 times in my form, what should I do in order to keep the second and the third time script independent from each other.

 

 

Thank you,

 

<html>
<body>
<script type='text/javascript'>
function update(a)
{
if(a=='1' || a=='2')
{
document.getElementById("destination").innerHTML="<select name='combo2'><option>option A</option><option>Option B</option></select>";
}
}
</script>
<form name='form1'>
<table>
<tr>
  <td><select name='combo1'  onChange='update(this.value)'>
    <option value="" selected>Select</option>
    <option value="1">1</option>
    <option value="2">2</option>

  </select></td>
</tr>
<tr><td>
<span id='destination'>
<select name='combo2' disabled='disabled' >
<option selected>Select combo 1 first</option>
</select>
</span>
</td></tr>

</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/224620-dependent-drop-down-list/
Share on other sites

When I choose option 1, the other field will be enabled;

 

 

I need to re-put the same fields twice in the same form like:

Select        Combo 1 first

 

Select        Combo 1 first

 

Select        Combo 1 first

 

 

the problem is when I choose select in line 2  "the combo 1 first" of the first line will change

this is the code:

 

<html>
<body>
<script type='text/javascript'>
function update1(a)
{
if(a=='1' || a=='2')
{
document.getElementById("destination").innerHTML="<select name='combo2'><option>option A</option><option>Option B</option></select>";
}
}

</script>
<form name='form1'>
<table>
<p>First:</p>
<tr>
  <td><select name='combo1'  onChange='update1(this.value)'>
    <option value="" selected>Select</option>
    <option value="1">1</option>
    <option value="2">2</option>

  </select></td>
</tr>
<tr><td>
  <p><span id='destination'>
    <select name='combo2' disabled='disabled' >
      <option selected>Select combo 1 first</option>
    </select>
  </span></p>
  <p><script type='text/javascript'>
function update2(a)
{
if(a=='1' || a=='2')
{
document.getElementById("destination2").innerHTML="<select name='combo4'><option>option A</option><option>Option B</option></select>";
}
}

</script></p>
  <p> </p>
  <p>Second</p>
  <p> </p>
  <p>
    <select name='combo3'  onChange='update2(this.value)'>
      <option value="" selected>Select</option>
      <option value="1">1</option>
      <option value="2">2</option>
    </select>
  </p>
  <p>
    <span id='destination2'><select name='combo4' disabled='disabled' >
      <option selected>Select combo 1 first</option>
    </select></span>
  </p></td></tr>

</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.