1

We have the following form:

<form>
...
 <table width="100%" cellspacing="0" class="datagrid_ppal">
 <tbody>
 <tr>
 <th scope="row">Area 1 <input name="config_line" type="hidden" value="0,5,50" /></th>
 <td class="gantt"> </td>
 <td class="gantt"> </td>
 <td class="gantt"> </td>
 ...
 </tr>
 </tbody>
 </table width="100%" cellspacing="0" class="datagrid_ppal">
...
<form>

What we need is to get the first, second or third from the hidden input value. We have tried this and didn't work:

 var value = $('th').children('input:hidden').val();

Can anyone help us? We would really appreciate it.

asked Jun 1, 2010 at 14:32
3
  • 1
    Are you saying that you can't get the value at all? $('th') is selecting all the th elements on the page. Are there others? .val() will return the value of the first th it finds on the page. Commented Jun 1, 2010 at 14:43
  • (I meant the say the value of the <input> in the first th .) Commented Jun 1, 2010 at 16:12
  • They will be several .val() in the same page. I'm trying to build some sort of Gantt chart. Commented Jun 1, 2010 at 19:27

3 Answers 3

1

The value of your hidden field is not an array, but just the string: "0,5,50".

To retrieve that value using jQuery use:

$('input[name=config_line]').val()

To split that string into an array use the split() method.

Combined:

var firstValue = $('input[name=config_line]').val().split(",")[0]; // etc...
answered Jun 1, 2010 at 14:36
Sign up to request clarification or add additional context in comments.

2 Comments

sorry, didn't see that. you can also use $('input[name=config_line]') as selector
Please change your answer, #config_line can be misleading.
0
var value = $('input[name=config_line]').val();
var valueArry = value.split(',');
var v1 = valueArry[0];
var v2 = valueArry[1];
var v3 = valueArry[2];
answered Jun 1, 2010 at 14:40

Comments

0

You'll find details Here .

var value = $('th').children("input[type='hidden']").val();

should work.

answered Jun 1, 2010 at 14:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.