1

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='philly@store.com'>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.

hyperj123
  • 23
  • 6

1 Answers1

1

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='philly@store.com'>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

Community
  • 1
  • 1
Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
  • Thank you! I will be accepting your answer as soon as it lets me. May I ask why it needs to be `.text` instead of `.name`? – hyperj123 Feb 09 '15 at 12:51
  • 1
    @hyperj123 If you check the [MDN documentation for ` – Rahul Desai Feb 09 '15 at 12:57