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!

Which event changes the selection in a list

Status
Not open for further replies.

nivone

Programmer
Jul 2, 2002
33
IL
HI,

I have textarea and a listbox with values.
I want that in case user sets the focus on the textarea the value displayed in the listbox will change to one of the values in the list, for example, to the first on the list.
 
<form name=form1>
<textarea onfocus=&quot;document.form1.ListBox.selectedIndex=1&quot; cols=20 rows=20></textarea>
<select name=&quot;ListBox&quot;>
<option value=&quot;&quot;>
<option value=&quot;1&quot;>1
<option value=&quot;2&quot;>2
</select>
</form>
 
HI,

I've tried it but it doesn't work. Here is my code:

<td width=&quot;340&quot; height=&quot;25&quot;><font face=&quot;Arial&quot;><b><input type=&quot;text&quot; name=&quot;owner&quot; size=&quot;20&quot; value=&quot;$rec[2]&quot; onFocus=&quot;document.form1.owner1.selectindex=0&quot;>

form1 is the name of the form.
owner1 is the name of the list

thanks
 
Hi nivone,

You have 2 syntax faults:

1) It is selected and not select
2) javascript is case sensitive: Index

so here is the right code (just as sjravee did)
<input type=&quot;text&quot; name=&quot;owner&quot; size=&quot;20&quot; value=&quot;$rec[2]&quot; onFocus=&quot;document.form1.owner1.selectedIndex=0&quot;>

Hope this helsp,
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top