0

I have two array hidden input and I am trying to access a value at a specific index using jQuery. My code

for ($i = 0; $i < count($mydata); $++){
 echo "<input type='hidden' name='menu_name[]' value='{$mydata[$i]->getname()}' />
       <input type='hidden' name='menu_rec[]' value='{$mydata[$i]->getrec()}' />";

Using jQuery I want to get the value of menu_name in index 2 for example;

What I am doing so far using jQuery

$('input[name=menu_name]:eq(1)').val();

I am getting undefined

2 Answers 2

1

Try this -

$('input[name="menu_name[]"]:eq(1)').val();
Sign up to request clarification or add additional context in comments.

2 Comments

@DevZer0 Because , in your fiddle you have only one menu_name[] . see this demo ---> jsfiddle.net/4bWAC/1
Excellent it is working like a charm. I did not know you can reference a name like that but now I do.
0

Try

$('input[name="menu_name[]"]:eq(1)')

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.