hyperj123
hyperj123

Reputation: 23

Why is my output undefined

I can't seem to figure this out. I am getting an undefined instead of philadelphia output on this script.

<center>
<form NAME="logform">
<select SIZE="1" NAME="store">
<option name='Philadelphia' id ='Joe Smith' value='[email protected]'>Philadelphia</option>
</select>
<br><br>
<input LANGUAGE="JavaScript" TYPE="button" VALUE="Send email"
ONCLICK="location.href = &quot;mailto:&quot; +
document.logform.store.options
[document.logform.store.selectedIndex].
value + &quot;?subject=I would like to buy the &quot; +
document.logform.store.options
[document.logform.store.selectedIndex].
name + &quot; location &quot;"
NAME="Send email">
</form>
</center>

Thanks for the help.

Upvotes: 1

Views: 107

Answers (1)

Rahul Desai
Rahul Desai

Reputation: 15481

Instead of:

document.logform.store.options[document.logform.store.selectedIndex].name

Use:

document.logform.store.options[document.logform.store.selectedIndex].text

Notice that just .name at the end was replaced by .text.

Working Code Snippet:

<center>
<form NAME="logform">
<select SIZE="1" NAME="store">
<option name='Philadelphia' id ='Joe Smith' value='[email protected]'>Philadelphia</option>
</select>
<br><br>
<input LANGUAGE="JavaScript" TYPE="button" VALUE="Send email"
ONCLICK="location.href = &quot;mailto:&quot; +
document.logform.store.options
[document.logform.store.selectedIndex].
value + &quot;?subject=I would like to buy the &quot; +
document.logform.store.options[document.logform.store.selectedIndex].text + &quot; location &quot;"
NAME="Send email">
</form>
</center>

Source

Upvotes: 1

Related Questions