0

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

3
Contributors
2
Replies
9
Views
4 Years
Discussion Span
Last Post by radhakrishna.p
0

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
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.