AddRowTable en jQuery escribir selectivamente en el cuadro de entrada

How do I get the value clicked in each row (generated using AddRowTable plugin), i.e.,

<script type="text/javascript">
$(".addRow-Max4").btnAddRow({maxRow:4, inputBoxAutoNumber:true});

generates maximal 4 rows in a table and numbers each input box, so I get textfield1, textfield2 and so onin my table.

<table border="0" >
    <th colspan="2">Input your data</th>
    <th><input type="button" value="Add Row" class="addRow-Max4"/></th>
    <a href="#" class="autofill">Apple</a> 
    <a href="#" class="autofill">Banana</a> 
    <a href="#" class="autofill">Mango</a>
    </td><td><input type="text" name="textfield" class="autofill" size="25"/></td>
    <td><img src="./images/cross.gif" class="delRow" border="0"></td>

Now I might decide for Apple in row1, Mango in row2 and so on and would like that the according textfield for this row is filled.

Intenté algo como:

return false;

but do not get it to work for the different textfields.

¿Alguna idea?

Ok now I have

$("a[class=autofill]").live("click", function(){
return false;

but how do I have to adjust it to make it dynamic for each row. Let's say textfield1, textfield2, textfield3 and so on.

preguntado el 01 de febrero de 12 a las 14:02

1 Respuestas

I just took a quick look, but I think maybe click() is not taking effect on elements used after the click event is defined. Try live() en lugar: $("a[class=autofill]").live("click", function(){ ... });

Respondido 01 Feb 12, 18:02

If these rows are added after the page has loaded, you cannot bind events to them as you have done. Zach L is correct that you have to use "live" to bind events to elements added to the DOM after the page is loaded. You can also use .delegate() - JT

ok using "live" now. One more question: how to call each different row here: $("input[name=textfield]").val($(this).text()); Thanks - user1182888

Can you explain a little more? I am kindof confused as to what exactly you want. - Zach Lysobey

Sorry for confusion, I edited my post, hopefully it is more clear what I want to do now... - user1182888

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.