Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

collecting values from listboxes?

Status
Not open for further replies.

moley

IS-IT--Management
Mar 26, 2002
95
GB
How do I get the values from a select box with an onChange on the first, adding options to the second??

I have the code to do this, but i'm getting an error 'object expected' on the first line below.

Code:
<select name="listOne" onClick="changeOptions(this, document.form1.listTwo);">

<option value="">Please select</option>	
<option value ="1">Telephone</option>
<option value ="2">Correspondence</option>
</select>  

<select name="listTwo" >
<option value="">Please Select </option>
[\code]

Any help would be great
 
Hope the following help
Code:
<script>
function changeOptions(sourceList, targetList) {
  if (sourceList.selectedIndex>0) {
    var newText=sourceList.options[sourceList.selectedIndex].text;
    var newValue=sourceList.options[sourceList.selectedIndex].value;
    targetList.options[targetList.length]=new Option(newText, newValue);
  }
}
</script>

<body>
<form name="form1">

<select name="listOne" size=3 onChange="changeOptions(this, document.form1.listTwo);">
<option value="">Please select</option>    
<option value ="1">Telephone</option>
<option value ="2">Correspondence</option>
</select>

<select name="listTwo" size=3>
<option value="">Please Select </option>
</select>
</form>
<body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top