0

I'm appending rows to a table using the jQuery tmpl plugin. Each row corresponds to three input fields, and a 'save' link. Save links I'm detecting using:

$(".saveClick").live('click',function(){
// 1. get 3 values for the row in question (stuck here)
// 2. process values via ajax (no problems here)
// 3. create new row from template (no problems here)

});

I can do the AJAX stuff to process the values, I just don't know what's the best way to access the values?

Any advice would be swell.

Thanks

Edit:

for clarification HTML:

<table id=inputTable>
<tr>
<td>cola</td>
<td>colb</td>
<td>colc</td>
<td>&nbsp;</td>
</tr>
</table>

jQuery Template:

<script id="tmplAddRow" type="text/x-jquery-tmpl">
<tr>
<td><input id="inA"></td>
<td><input id="inB"></td>
<td><input id="inC"></td>
</tr>
</script>
Raoul
  • 3,849
  • 3
  • 24
  • 30

3 Answers3

0

So it seems that your question is really: "How can I access table cell values?"

That was asked before, so you can find the answer at How to get a table cell value using jQuery?.

Community
  • 1
  • 1
Roy Dictus
  • 32,551
  • 8
  • 60
  • 76
  • The values I'm interested in aren't cell values, rather text input fields. I've tried three of the solutions via that link and for each I get 'undefined' when trying to alert the value. – Raoul Jun 21 '11 at 13:51
  • If you can access the values in your function(), can't you store them in an array and then access that array later? – Roy Dictus Jun 21 '11 at 14:04
  • I tried the examples you linked to to access the values, and they all returned 'undefined' when I alerted them out – Raoul Jun 21 '11 at 14:13
  • Of course, because the examples access raw values in cells whereas you put textboxes in the cells. But if your js function() can receive and process the values in your step (2), in that step you should also be able to put them in an array, so that you can access that array from outside of your function. – Roy Dictus Jun 21 '11 at 14:17
  • I have no problems coding ajax stuff, as I stated in the question I can't get the values to use in step 2. – Raoul Jun 21 '11 at 14:19
0

if you use a table you can "return" up until relative at the row of your save link and after you can find the fields

$(".saveClick").parent().find("selector-of-field");
Michele
  • 3
  • 1
  • when I try this or assign it to a variable I get 'undefined' `var myref=$(".saveFile").parent().find("inA"); alert(myref);` – Raoul Jun 21 '11 at 14:25
0

example:

$(".saveClick").live('click',function(){


alert($(this).closes("tr").find("td:nth-child(1) input").val());


}
Raoul
  • 3,849
  • 3
  • 24
  • 30