Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input text value from inside td

Tags:

jquery

<tr>
 <td>
      <input type="text" name="desc[]">
 </td>
 <td>
      <input type="text" name="duration[]">
 </td>
 <td>
      <input type="text" name="start[]" class="start">
 </td>
 <td>
       <input type="text" name="wait[]">
 </td>
 <td>
       <input type="text" name="end[]">
 </td>
 <td>
      <input type="text" name="phone[]">
 </td>
</tr>

I have such multiple rows. I need to fetch the values off all tds on keyup event on the td with input name start(and i also need to avoid values of desc[] and phone[]). Since they are many i cannot go with ids, need help in parent child approach with jquery.

I was able to reach parent tr on keyup event on the above mentioned td but not able to access values of input field in other tds. the jquery code i used

$(document).ready(function(){
    $(".start").keyup(function(){
        alert($(this).parent().get(-3).tagName);
    })
});
like image 971
Ashish Rajan Avatar asked Mar 30 '10 15:03

Ashish Rajan


People also ask

How do I get text content of input?

We can get the value of the text input field using various methods in JavaScript. There is a text value property that can set and return the value of the value attribute of a text field. Also, we can use the jquery val() method inside the script to get or set the value of the text input field.

How do I get the value of a DOM input?

Answer: Use the value Property You can simply use the value property of the DOM input element to get the value of text input field.


1 Answers

Ah I think a understand now. Have a look if this really is what you want:

$(".start").keyup(function(){
    $(this).closest('tr').find("input").each(function() {
        alert(this.value)
    });
});

This will give you all input values of a row.

Update:
To get the value of not all elements you can use :not():

$(this).closest('tr').find("input:not([name^=desc][name^=phone])").each(function() {
     alert(this.value)
});

Actually I am not 100% sure whether it works this way, maybe you have to use two nots instead of this one combining both conditions.

like image 145
Felix Kling Avatar answered Sep 20 '22 16:09

Felix Kling