1

I have the following HTML:

<table>
<tr><td>...</td><td><input type="hidden" name="price[1]" value="10"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[6]" value="230"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[7]" value="40"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[10]" value="10"></td><td>...</td>
</table>

I have also got that this is important to say that they are stored in table tds and it's preferred not to bring them out of the table. (So I updated the code to be more like in real)

What I want, is a way to select one of them by their index() number to be able to get their val().

I know that their index is counted from 0 to 3. I want to get the val() of the second one with index(1).

2
  • 2
    You want to select one of them (which one?) or all of them? What do you want to do with the values? Commented Jun 27, 2013 at 6:55
  • 1
    I updated my answer to match your clarification. Commented Jun 27, 2013 at 7:05

4 Answers 4

4

To get the value of the second hidden input:

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

Comments

1

In jQuery it would be:

$('input[type="hidden"]');

http://jsfiddle.net/mattydsw/32NU8/

Comments

1

DEMO http://jsfiddle.net/yeyene/yGCP2/

$(document).ready(function(){
    $('input[type=hidden]').each(function(){
        alert($(this).val());
    });
});

1 Comment

Thank you. Maybe I was not clear enough. Any I appreciated your help.
1

try:

fiddle

var a="";
$("input[type=hidden]" ).each(function( index ) {
    a+=($(this).val()) + ",";

});
alert(a);

1 Comment

Thank you. Maybe I was not clear enough. Any I appreciated your help.

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.