• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

How to copy input form dropdown list value in HTML?

1-Having two input dropdown list in HTML code.
2-When selecting the first I want the second to go to the same selection.
3-I want to be able to change the selection in the second dropdown list without changing the first one.
Pllease  send me the Javascript code to do that?
Below the two input code.
Thanks
input one code:
<select name="XLEW_1_15_2" id="XLEW_1_15_2" size="1" onChange="recalc_onclick('XLEW_1_15_2')" tabindex="9" class='ee128' style=' width:100% '>
  <option value="<?php echo $Selstate;?>" selected><?php echo $Selstate;?></option>
  <option value="Alabama">Alabama</option>
  <option value="Alaska">Alaska</option>
  <option value="Arizona">Arizona</option>
  <option value="Arkansas">Arkansas</option>
  <option value="California">California</option>
  <option value="Carolina">Carolina</option>
  <option value="Colorado">Colorado</option>
  <option value="Columbia">Columbia</option>
  <option value="Connecticut">Connecticut</option>
  <option value="Dakota">Dakota</option>
  <option value="Delaware">Delaware</option>
  <option value="Florida">Florida</option>
  <option value="Georgia">Georgia</option>
  <option value="Guam">Guam</option>
  <option value="Hampshire">Hampshire</option>
  <option value="Hawaii">Hawaii</option>
  <option value="Idaho">Idaho</option>
  <option value="Illinois">Illinois</option>
  <option value="Indiana">Indiana</option>
  <option value="Iowa">Iowa</option>
  <option value="Islands">Islands</option>
  <option value="Jersey">Jersey</option>
  <option value="Kansas">Kansas</option>
  <option value="Kentucky">Kentucky</option>
  <option value="Louisiana">Louisiana</option>
  <option value="Maine">Maine</option>
  <option value="Maryland">Maryland</option>
  <option value="Massachusetts">Massachusetts</option>
  <option value="Mexico">Mexico</option>
  <option value="Michigan">Michigan</option>
  <option value="Minnesota">Minnesota</option>
  <option value="Mississippi">Mississippi</option>
  <option value="Missouri">Missouri</option>
  <option value="Montana">Montana</option>
  <option value="Nebraska">Nebraska</option>
  <option value="Nevada">Nevada</option>
  <option value="Ohio">Ohio</option>
  <option value="Oklahoma">Oklahoma</option>
  <option value="Oregon">Oregon</option>
  <option value="Pennsylvania">Pennsylvania</option>
  <option value="Rico">Rico</option>
  <option value="Samoa">Samoa</option>
  <option value="Tennessee">Tennessee</option>
  <option value="Texas">Texas</option>
  <option value="Utah">Utah</option>
  <option value="Vermont">Vermont</option>
  <option value="Virginia">Virginia</option>
  <option value="Washington">Washington</option>
  <option value="Wisconsin">Wisconsin</option>
  <option value="Wyoming">Wyoming</option>
  <option value="York">York</option>
  </select>
 
//input 2
<select name="XLEW_1_31_2" id="XLEW_1_31_2" size="1" onChange="recalc_onclick('XLEW_1_31_2')" tabindex="13" class='ee128' style=' width:100% '>
  <option value="Select State" selected>Select State</option>
  <option value="Alabama">Alabama</option>
  <option value="Alaska">Alaska</option>
  <option value="Arizona">Arizona</option>
  <option value="Arkansas">Arkansas</option>
  <option value="California">California</option>
  <option value="Carolina">Carolina</option>
  <option value="Colorado">Colorado</option>
  <option value="Columbia">Columbia</option>
  <option value="Connecticut">Connecticut</option>
  <option value="Dakota">Dakota</option>
  <option value="Delaware">Delaware</option>
  <option value="Florida">Florida</option>
  <option value="Georgia">Georgia</option>
  <option value="Guam">Guam</option>
  <option value="Hampshire">Hampshire</option>
  <option value="Hawaii">Hawaii</option>
  <option value="Idaho">Idaho</option>
  <option value="Illinois">Illinois</option>
  <option value="Indiana">Indiana</option>
  <option value="Iowa">Iowa</option>
  <option value="Islands">Islands</option>
  <option value="Jersey">Jersey</option>
  <option value="Kansas">Kansas</option>
  <option value="Kentucky">Kentucky</option>
  <option value="Louisiana">Louisiana</option>
  <option value="Maine">Maine</option>
  <option value="Maryland">Maryland</option>
  <option value="Massachusetts">Massachusetts</option>
  <option value="Mexico">Mexico</option>
  <option value="Michigan">Michigan</option>
  <option value="Minnesota">Minnesota</option>
  <option value="Mississippi">Mississippi</option>
  <option value="Missouri">Missouri</option>
  <option value="Montana">Montana</option>
  <option value="Nebraska">Nebraska</option>
  <option value="Nevada">Nevada</option>
  <option value="Ohio">Ohio</option>
  <option value="Oklahoma">Oklahoma</option>
  <option value="Oregon">Oregon</option>
  <option value="Pennsylvania">Pennsylvania</option>
  <option value="Rico">Rico</option>
  <option value="Samoa">Samoa</option>
  <option value="Tennessee">Tennessee</option>
  <option value="Texas">Texas</option>
  <option value="Utah">Utah</option>
  <option value="Vermont">Vermont</option>
  <option value="Virginia">Virginia</option>
  <option value="Washington">Washington</option>
  <option value="Wisconsin">Wisconsin</option>
  <option value="Wyoming">Wyoming</option>
  <option value="York">York</option>
  </select>

Open in new window

0
DLJB
Asked:
DLJB
1 Solution
 
mstrelanCommented:
Try this... make sure you set the onblue onclick and onkeypress events in the first select box only
<script>
function syncInputs() {
    document.getElementById('XLEW_1_31_2').selectedIndex = document.getElementById('XLEW_1_15_2').selectedIndex;
}
</script>
<select name="XLEW_1_15_2" id="XLEW_1_15_2" size="1" onChange="recalc_onclick('XLEW_1_15_2')" onblur="syncInputs();" onclick="syncInputs();" onkeypress="syncInputs();" tabindex="9" class='ee128' style=' width:100% '>
  <option value="<?php echo $Selstate;?>" selected><?php echo $Selstate;?></option>
  <option value="Alabama">Alabama</option>
  <option value="Alaska">Alaska</option>
  <option value="Arizona">Arizona</option>
  <option value="Arkansas">Arkansas</option>
  <option value="California">California</option>
  <option value="Carolina">Carolina</option>
  <option value="Colorado">Colorado</option>
  <option value="Columbia">Columbia</option>
  <option value="Connecticut">Connecticut</option>
  <option value="Dakota">Dakota</option>
  <option value="Delaware">Delaware</option>
  <option value="Florida">Florida</option>
  <option value="Georgia">Georgia</option>
  <option value="Guam">Guam</option>
  <option value="Hampshire">Hampshire</option>
  <option value="Hawaii">Hawaii</option>
  <option value="Idaho">Idaho</option>
  <option value="Illinois">Illinois</option>
  <option value="Indiana">Indiana</option>
  <option value="Iowa">Iowa</option>
  <option value="Islands">Islands</option>
  <option value="Jersey">Jersey</option>
  <option value="Kansas">Kansas</option>
  <option value="Kentucky">Kentucky</option>
  <option value="Louisiana">Louisiana</option>
  <option value="Maine">Maine</option>
  <option value="Maryland">Maryland</option>
  <option value="Massachusetts">Massachusetts</option>
  <option value="Mexico">Mexico</option>
  <option value="Michigan">Michigan</option>
  <option value="Minnesota">Minnesota</option>
  <option value="Mississippi">Mississippi</option>
  <option value="Missouri">Missouri</option>
  <option value="Montana">Montana</option>
  <option value="Nebraska">Nebraska</option>
  <option value="Nevada">Nevada</option>
  <option value="Ohio">Ohio</option>
  <option value="Oklahoma">Oklahoma</option>
  <option value="Oregon">Oregon</option>
  <option value="Pennsylvania">Pennsylvania</option>
  <option value="Rico">Rico</option>
  <option value="Samoa">Samoa</option>
  <option value="Tennessee">Tennessee</option>
  <option value="Texas">Texas</option>
  <option value="Utah">Utah</option>
  <option value="Vermont">Vermont</option>
  <option value="Virginia">Virginia</option>
  <option value="Washington">Washington</option>
  <option value="Wisconsin">Wisconsin</option>
  <option value="Wyoming">Wyoming</option>
  <option value="York">York</option>
  </select>
 
 
<select name="XLEW_1_31_2" id="XLEW_1_31_2" size="1" onChange="recalc_onclick('XLEW_1_31_2')"  tabindex="13" class='ee128' style=' width:100% '>
  <option value="Select State" selected>Select State</option>
  <option value="Alabama">Alabama</option>
  <option value="Alaska">Alaska</option>
  <option value="Arizona">Arizona</option>
  <option value="Arkansas">Arkansas</option>
  <option value="California">California</option>
  <option value="Carolina">Carolina</option>
  <option value="Colorado">Colorado</option>
  <option value="Columbia">Columbia</option>
  <option value="Connecticut">Connecticut</option>
  <option value="Dakota">Dakota</option>
  <option value="Delaware">Delaware</option>
  <option value="Florida">Florida</option>
  <option value="Georgia">Georgia</option>
  <option value="Guam">Guam</option>
  <option value="Hampshire">Hampshire</option>
  <option value="Hawaii">Hawaii</option>
  <option value="Idaho">Idaho</option>
  <option value="Illinois">Illinois</option>
  <option value="Indiana">Indiana</option>
  <option value="Iowa">Iowa</option>
  <option value="Islands">Islands</option>
  <option value="Jersey">Jersey</option>
  <option value="Kansas">Kansas</option>
  <option value="Kentucky">Kentucky</option>
  <option value="Louisiana">Louisiana</option>
  <option value="Maine">Maine</option>
  <option value="Maryland">Maryland</option>
  <option value="Massachusetts">Massachusetts</option>
  <option value="Mexico">Mexico</option>
  <option value="Michigan">Michigan</option>
  <option value="Minnesota">Minnesota</option>
  <option value="Mississippi">Mississippi</option>
  <option value="Missouri">Missouri</option>
  <option value="Montana">Montana</option>
  <option value="Nebraska">Nebraska</option>
  <option value="Nevada">Nevada</option>
  <option value="Ohio">Ohio</option>
  <option value="Oklahoma">Oklahoma</option>
  <option value="Oregon">Oregon</option>
  <option value="Pennsylvania">Pennsylvania</option>
  <option value="Rico">Rico</option>
  <option value="Samoa">Samoa</option>
  <option value="Tennessee">Tennessee</option>
  <option value="Texas">Texas</option>
  <option value="Utah">Utah</option>
  <option value="Vermont">Vermont</option>
  <option value="Virginia">Virginia</option>
  <option value="Washington">Washington</option>
  <option value="Wisconsin">Wisconsin</option>
  <option value="Wyoming">Wyoming</option>
  <option value="York">York</option>
  </select>

Open in new window

0
 
HonorGodCommented:
Note:

If the "value" attribute is identical the the stuff between the opening and closing "option" tags, then you don't have to specify the value attribute.

So, these option tags are identical:



<option value="Alabama">Alabama</option>
 
 
<option>Alabama</option>

Open in new window

0
 
DLJBAuthor Commented:
Thanks very much.
It really works!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now