views:

65

answers:

6

I use the following selector to get the value out of an input that's inside a table but it doesnt work properly?

var kom =$("tr#1 .b input").attr(value);

and row looks as follow

  <tr class="numbers" id="1">
   <td class="a" align="right">1</td>
   <td class="a" align="left">Tue</td>
   <td class="b"><input class="input" type="text" title="" value=""/></td>
   <td class="c"><input class="input" type="text" title="" value=""/></td>
   <td class="d"><input class="input" type="text" title="" value=""/></td>
   <td class="e"><input class="input" type="text" title="" value=""/></td>
   <td class="f">0</td>
   <td class="g"><input class="input" type="text" title="" value=""/></td>
 </tr>

any suggestion on what i might be doing wrong any aid is greatly appreciated

regards breezer

+4  A: 

Try putting value in quotes.

Simon Brown
+6  A: 

Two problems here, first your IDs should not start with a number, use a prefix, like row1, then use .val() to get the value, like this:

var kom =$("tr#row1 .b input").val();

If you were to use .attr(), you would use it like this .attr('value'), currently it's looking for .attr(undefined). I put if in italics because you should pretty much always use .val() to get or set a value on an <input>...same goes for <select> and <textarea>.

Nick Craver
I assume "your IDs should start with a number" should read "your IDs should **not** start with a number" ?
Stephen P
@Stephen - Oops, good catch, thanks :)
Nick Craver
+1 for the id rules, though specifying tr is superfluous.
edl
@edl - Agreed, I prefer to change as little as possible from the question to demonstrate only the egregious problems though :) Good note none the less, unless there's the possibility of this same ID on another element type that shouldn't match, it's extraneous.
Nick Craver
the actual problem was the quotes but I appreciate the recommendations for the other things so ill mark this as the accurate answer
Breezer
+2  A: 

Accessing the DOM's value attribute can be a bit funky. Try this:

var kom =$("tr#1 .b input").val();
Oli
A: 

$("tr#1 .b input").attr("value");

watch that you havent enclosed value in "value"

sushil bharwani
A: 

This is what you want:

var kom = $(".b input").val();

TimDog
A: 
var kom =$("tr#1 .b input").attr("value")

or better

var kom =$("tr#1 .b input").val();
Spyros