Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  28] [ 2]  / answers: 1 / hits: 59870  / 14 Years ago, mon, july 26, 2010, 12:00:00

I'm looping through cells in a table row. each cell has a text box in it, and I want to take the value of the text box and push it onto an array.



function dothing() {
var tds = $('#'+selected+' td');
var submitvals = new Array();
tds.each(function(i) {
var val = $(this).children('input')[0].val();
submitvals.push(val);
});
}


Theres more to the function, but this is all that is relevant. For some reason, when I run this code, I get HTMLInputElement has no method 'val'. I thought that input elements were supposed to have a val() method in jQuery that got the value so this makes no sense. Am I missing something, or doing it wrong?


More From » jquery

 Answers
76

val() is a jQuery method. .value is the DOM Element's property. Use [0].value or .eq(0).val()....


[#96110] Friday, July 23, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominiquezachariahh

Total Points: 343
Total Questions: 81
Total Answers: 106

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;