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
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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.