Lewis Lewis - 11 days ago 6
PHP Question

Validating HTML Drop-down menu with Javascript?

I'm trying to validate a login script, pretty much everything else is done but I don't know how to do a drop-down menu. How would I validate it, to ensure an option other than the default is selected, through JavaScript?

All of the other validation is done via a separate .js sheet, so I'm not sure if document.getElementById works or I'm just making silly mistakes?

HTML (Form ID is "registration_form"):

<select class="signup_input_styleV2" id="location" name="location">
<option value="false" disabled selected>Region</option>
<option value="Europe">Europe</option>
<option value="North America">North America</option>
<option value="South America">South America</option>
<option value"Oceania">Oceania</option>
<option value"Asia">Asia</option>
<option value"Africa">Africa</option>
<option value"Antarctica">Antarctica</option>
</select>

Answer
 if ( document.getElementsByName('location')[0].value == 'false' ){
    alert('Select something !');
}

This might suffice.