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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting data from drop down list 1

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
Hi.

I have a list of data that is something along the following:

<select name="samplelist">
<option value="1">Item 1</option>
<option value="3">Item 2</option>
<option value="6">Item 3</option>
<option value="18">Item 4</option>
<option value="36">Item 5</option>
<option value="235">Item 6</option>
</select>

I want it so when I click a button it takes the value of another field and finds it in this drop down and select it.

I have found many scripts but they dont appear to work correctly. They seem to go for the index rather then the value. So if this value in the other field is 3 and I click the button it selects Item 3, which is incorrect. It should select Item 2 but as Item 3 is in index '3' thats the item selected.

Any help would be appreciated.

Thanks!

- FateFirst
 
If you know that the value entered will match an element in the select list, this will work:
Code:
document.forms['form1'].elements['samplelist'].value = document.forms['form1'].elements['daTextBox'].value;
Otherwise you'll have to loop thru the options until you find one whose .value is the same as the text box .value.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Thanks :)

I thought I had tried that....guess not...or I did it wrong.

- FateFirst
 
You might have forgotten either or both of the .value attributes. Depending on the context, that may not work, but may not give you an error either.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top