Scott Paterson Scott Paterson - 7 months ago 10
HTML Question

this.defaultValue returns undefined for select element

Normal HTML dropdown menu:

<select name="email" id="email">
<option value="2" selected="selected">Before redirecting to PayPal</option>
<option value="1">After payment is successful</option>
<option value="3">Never send email</option>
</select>


Using jQuery
this.defaultValue
returns 'undefined'.

Using
$(this).val()
returns '2', correctly.

Why is
this.defaultValue
returning 'undefined'?

Answer

As described on W3C, defaultValue works only with certain types of the elements

defaultValue of type DOMString
When the type attribute of the element has the value "text", "file" or "password" (...)