manojadams
manojadams

Reputation: 2430

Get field value by name

I have the following input field:

<input type="hidden" name="field_tab_order[0]" />

How to access this using name attribute with jQuery. This must be easy. I am having trouble trying to access it like this:

jQuery('input[name=field_tab_order[0]]');

Upvotes: 0

Views: 80

Answers (3)

adeneo
adeneo

Reputation: 318182

must quote

jQuery('input[name="field_tab_order[0]"]');

or escape

jQuery('input[name=field_tab_order\\[0\\]]');

when using certain characters in selector

Because jQuery uses CSS syntax for selecting elements, some characters are interpreted as CSS notation.

For example, periods, colons, braces etc. are problematic within the context of a jQuery selector because they indicate another atttribute selector nested in the first etc.

In order to tell jQuery to treat these characters literally rather than as CSS notation, they must be "escaped" by placing two backslashes in front of them.

Upvotes: 4

LittleDragon
LittleDragon

Reputation: 2437

var value =  $('input[name="field_tab_order[0]"]').val();

Upvotes: 1

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

you have to put quotes for name attribute value like this:

jQuery('input[name="field_tab_order[0]"]');

Upvotes: 2

Related Questions