user3357400
user3357400

Reputation: 397

check input type text and radio

Here: http://jsfiddle.net/B9r22/22/ I create a form with radio button and text input. I would like to check if in form all inputs are completed. I know check radio button, but text input is not working properly. Can you check my code?

if ($('input[name="age"].value') == null || $('input[name="age"].value') == "") {
alert("is filled");
}
else {
alert("is not filled");
}

Upvotes: 0

Views: 40

Answers (3)

Gaurang Tandon
Gaurang Tandon

Reputation: 6753

Should be

if ($('input[name="age"]').val() == "") { 
    alert("is filled");
}else {
    alert("is not filled");
}

You had set it to input[name="age"].value, which means get an <input> element with a name attribute having value age and a class value.

Hope that helps!

Upvotes: 0

Abhay Prince
Abhay Prince

Reputation: 2162

You are using it wrong, use

$('input[name="age"]').val() == null

Upvotes: 0

bingjie2680
bingjie2680

Reputation: 7773

working example: http://jsfiddle.net/B9r22/24/

if ($('input[name=age]').val() === "") {
     alert("is not filled");
} else {
    alert("is filled");
}

Upvotes: 2

Related Questions