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

selecting option from drop down that equals a value in a textbox

Status
Not open for further replies.

guestAsh

Technical User
Feb 27, 2004
65
GB
hi,

I have a select box (drop down) on a form and i need it to automatically default to the selected option that matches a value in a textbox (hidden) on the same page.

i've tried using the following, but nothing happens, i don't even get any error messages.

any idea where i'm going wrong?

for info:

The hidden text box is called hide_5
and the select is called q_5

Code:
  <script language="vbscript">
	For n = 0 to document.frmspa.q_5.options.length - 1

    If document.frmspa.q_5.options[n].text = document.frmspa.hide_5.value Then
	  
	        document.frmspa.q_5.selectedIndex = n
	       Exit For
	   End If
	Next
</script>
 
[1]
[tt]
<script language="vbscript">
[blue]sub window_onload[/blue]
For n = 0 to document.frmspa.q_5.options.length - 1
If document.frmspa.q_5.options[red]([/red]n[red])[/red].text = document.frmspa.hide_5.value Then
document.frmspa.q_5.selectedIndex = n
Exit For
End If
Next
[blue]end sub[/blue]
</script>
[/tt]
[2] If the option's value is scripted exactly equal to its text - option's value is the actual data to be consumed by the server, not the text - you can simply do this.
[tt]
<script language="vbscript">
sub window_onload
document.frmspa.q_5.value = document.frmspa.hide_5.value
end sub
</script>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top