codeMan
codeMan

Reputation: 5758

Select a input field in jquery based on name

I am using jquery form validator to validate all my fields in the form.

In form validator I am using following code to see if a input field has the name minExperience.

errorPlacement: function(error, element) {
    if(/*Want to check if the `element` has the name = "minExperience"*/) 
    {
        error.insertAfter($('#skillBtn'));
    }
}

So that I can place the error message after $('#skillBtn').

I am not able to figure out what to write in the if condition.

Please help.

Upvotes: 0

Views: 896

Answers (4)

David Jiboye
David Jiboye

Reputation: 511

Simply put as

 if (element.attr("name") == "minExperience")
 {
           error.insertAfter($('#skillBtn'));
 }

Upvotes: 0

Jaykishan
Jaykishan

Reputation: 1499

You can use $('input[name=\'name_field\']').val() and then compare it depends your conditions.

Upvotes: 2

Rohan Kumar
Rohan Kumar

Reputation: 40639

Try this,

errorPlacement: function(error, element) {
    if(element.attr('name')=='minExperience') 
    {
        error.insertAfter($('#skillBtn'));
    }
}

Upvotes: 3

karthikr
karthikr

Reputation: 99660

If you are looking for <input name="minExperience" /> you can do

alert($('input[name="minExperience"]').val())

Upvotes: 1

Related Questions