[Javascript] My code works in IE, not in Netscape, please help
Peter Brunone
peter at brunone.com
Mon Apr 23 12:57:02 CDT 2001
Yi,
The correct way to refer to the VALUE of an OPTION tag is like this:
document.mailinfo.name.options[document.mailinfo.name.selectedIndex].value
Each SELECT structure has an array called options that contains elements
for each of the OPTION choices. You can put 1, 2, or 3 inside the brackets
[] to hard-code the value. The SELECT also has a property called
selectedIndex that gives a number to show which option is selected.
Similarly, you can get the visible text in the option with this code:
document.mailinfo.name.options[document.mailinfo.name.selectedIndex].text
Cheers,
Peter
----- Original Message -----
From: "Yi Li" <yili1998 at yahoo.com>
To: <javascript at LaTech.edu>
Sent: Monday, April 23, 2001 12:02 PM
Subject: [Javascript] My code works in IE, not in Netscape, please help
> Hi, Everyone:
>
> I try to create a stationary, all names in
> <select></select>, when select a name, other input box
> pop up correct mail address. My code works in IE, but
> not in Netscape, please help with following code:
> -------------------------------------------------------
>
> <HTML>
> <HEAD>
> <TITLE>Stationary</TITLE>
> <SCRIPT LANGUAGE="JavaScript1.2">
> <!-- HIDE FROM INCOMPATIBLE BROWSERS
> function chooseName()
> {
> if (document.mailinfo.name.value == "Bunny Bug")
> {
> document.mailinfo.address.value = "12345 Sunny
> Drive";
> document.mailinfo.city.value = "Farmland";
> document.mailinfo.state.value = "MS";
> document.mailinfo.zip.value = "39180";
> document.mailinfo.dear.value = "Ms. Bunny Bug:";
> }
> else if (document.mailinfo.name.value == "Donld
> Dock")
> {
> document.mailinfo.address.value = "56789 Beverly
> Lane";
> document.mailinfo.city.value = "San Jose";
> document.mailinfo.state.value = "CA";
> document.mailinfo.zip.value = "95121";
> document.mailinfo.dear.value = "Mr. Donld Dock:";
> }
> else
> {
> document.mailinfo.address.value = "111213 E.
> Watcher Dr.";
> document.mailinfo.city.value = "Topsy";
> document.mailinfo.state.value = "UT";
> document.mailinfo.zip.value = "84121";
> document.mailinfo.dear.value = "Mickey Mouse:";
> }
> }
> // STOP HIDING FROM INCOMPATIBLE BROWSERS -->
> </SCRIPT>
> </HEAD>
> <BODY bgcolor=#FFFFCC>
> <FONT face="verdana">
> <H1 align="CENTER">My Stationery</H1>
> <HR>
> <FORM NAME="mailinfo">
> Name:<BR>
> <SELECT NAME="name" onChange="chooseName( );">
> <OPTION VALUE="0">--- Select Name ---
> <OPTION VALUE="Bunny Bug">Bunny Bug
> <OPTION VALUE="Donld Dock">Donld Dock
> <OPTION VALUE="Mickey Mouse">Mickey Mouse
> </SELECT><BR>
> Address:<BR>
> <INPUT TYPE="text" NAME="address" SIZE=30><BR>
> City, State, Zip:<BR>
*snip*
More information about the Javascript
mailing list