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

Reset to default value after select in form

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

Using code similar to
Code:
<FORM>
<SELECT ONCHANGE="location = this.options[this.selectedIndex].value;">
<OPTION VALUE="myhome.html">My Home Page
<OPTION VALUE="myresume.html">Resume
<OPTION VALUE="myhobbies.html">Hobbies
<OPTION VALUE="mydog.html">My Dog
</SELECT>
</FORM>
can the ONCHANGE or some other event be used to reset the default value to 'My Home Page'?

TIA


FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Rightly or wrongly, this does the trick
Code:
<FORM>
<SELECT ONCHANGE="location = this.options[this.selectedIndex].value;[COLOR=red]this.selectedIndex='My Home Page';[/color]">
<OPTION VALUE="myhome.html">My Home Page
<OPTION VALUE="myresume.html">Resume
<OPTION VALUE="myhobbies.html">Hobbies
<OPTION VALUE="mydog.html">My Dog
</SELECT>
</FORM>
Any better way?

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
I would have used either:

Code:
this.selectedIndex = 0

or

Code:
this.value = 'myhome.html'

The latter would be better as then you could re-order the items without any change to the code.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
don't forget to close each option!

Code:
<FORM>
<SELECT ONCHANGE="location = this.options[this.selectedIndex].value;this.selectedIndex='My Home Page';">
<OPTION VALUE="myhome.html">My Home Page[COLOR=red][b]</OPTION>[/b][/color]
<OPTION VALUE="myresume.html">Resume[COLOR=red][b]</OPTION>[/b][/color]
<OPTION VALUE="myhobbies.html">Hobbies[COLOR=red][b]</OPTION>[/b][/color]
<OPTION VALUE="mydog.html">My Dog[COLOR=red][b]</OPTION>[/b][/color]
</SELECT>
</FORM>


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
vicverk

Thanks for your comments.

My somewhat limited understanding is that in HTML the <option> tag has no end tag.

In XHTML the <option> tag must be properly closed.

As its intended use is in a simple HTML page, the end tag was omitted.

Would appreciate further clarification on the issue.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top