ChrisBedoya
ChrisBedoya

Reputation: 747

Help withJS Form Validation

I'm working on a js form validation and so far I have this:

        // grab form field values
    var valid = '';
    var name = $('form #name').val();

    // perform error checking
    if (name = '' || name.length <= 2) {
        valid = '<p>Your name' + required +'</p>';
    }

How can I validate that the user has chosen one of the options from a dropdown that I have in my form?

Thanks in advance.

Upvotes: 1

Views: 59

Answers (2)

zod
zod

Reputation: 12417

$('select.foo').val(); 

check this

http://api.jquery.com/val/

Upvotes: 3

Matthew Nessworthy
Matthew Nessworthy

Reputation: 1428

if($('select.your-class-here').val() !== '') { //value select

} else { //nothing selected

}

Upvotes: 1

Related Questions