I'm in the end stages of my program and everything is running fine, all i need to do now is create some data validation for my form.

I've dabbled around and have figures out how to validate textboxes but am not sure how to validate my drop down boxes.

So my if statement to validate is

    if (Verb == "")
    {
        alert( "Please pick a valid option");
        document.LimGenerator.Name.focus() ;
    }
    return false;

and my html is

<td> Pick a past tense verb </td><td><select name="Verb" size="1" value="up" id="Verb">
    <option value="">Please Choose</option>
    <option value="1">Sat</option>
    <option value="2">Jumped</option>
    <option value="3">Hopped</option>
</select><br /></td></tr>

Hope you can help

ChargrO

Recommended Answers

All 2 Replies

validation is correct but i think you are taking wrong value of Verb

Use

var Verb = VerbSelect.options[VerbSelect.selectedIndex].value;//you are using  .text ,it will return text but you want value

hai ChargrO,

try this (is also valid)

var VerbSelect = document.getElementById('Verb');

var Verb_text = VerbSelect.options[VerbSelect.selectedIndex].text;
          (or) 
var Verb_val = VerbSelect.options[VerbSelect.selectedIndex].value;

let me know the status

happy coding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.