2

can you help me. I need select with JQuery input with name and input with name in array.

<input type="text" name="name">
<input type="text" name="shippingAddress[name]">

I try this, but this not work.

var name = $('[name^="name"]');
3
  • Is shippingAddress[name] supposed to be the value of the name attribute or its own attribute? Commented Mar 28, 2013 at 9:40
  • shippingAddress[name] what is this? Commented Mar 28, 2013 at 9:40
  • Sorry, Now it is good., bat I need find, by name Commented Mar 28, 2013 at 9:44

3 Answers 3

1

You could use the attribute-contains selector:

var name = $('[name*="name"]');

That will select any element where its name attributes value contains the substring "name", so will match both <input type="text" name="name"/> and <input type="text" name="shippingAddress[name]"/>.

Sign up to request clarification or add additional context in comments.

Comments

0

try attribute selector

var name = $('[name^="shippingAddress\\[name\\]]');

Comments

0

To select input with name:

$('input[name=name]')

To select input with name as array field:

$('input[name="' + shippingAddress + '[]"]')   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.