replace - cloning elements with jquery -



replace - cloning elements with jquery -

i working on form user can add together rows wants to. there link named "add row", when clicked, want clone hidden table , alter it's name values, of class names. help me this?

<table class="montaj montaj-satir"> <tr> <td width="62px"><input type="text" name="oper[--number--][kodu]" size="4" maxlength="4" /></td> <td width="38px"> <input type="checkbox" name="oper[--number--][onay]" value="1" /> <input type="hidden" name="oper[--number--][terminal_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][soket_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][montaj_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][yon_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][push_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][olcu_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][bant_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][vida_hatasi]" value="0" /> <input type="hidden" name="oper[--number--][komponent_hatasi]" value="0" /> </td> <td width="62px"><span class="terminal_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="terminal_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="soket_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="soket_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="montaj_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="montaj_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="yon_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="yon_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="push_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="push_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="olcu_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="olcu_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="bant_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="bant_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="vida_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="vida_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> <td width="62px"><span class="komponent_hatasi--number--">0</span> <a href="#" class="add hata-ekle" id="komponent_hatasi--number--">&nbsp; &nbsp; &nbsp;</a></td> </tr> <tr> <td colspan="2">kablo sıra no</td> <td colspan="4"><input type="text" name="oper[--number--][kablo_sira_no]" value="" /></td> <td colspan="2">açıklama</td> <td colspan="3"><input type="text" name="oper[--number--][aciklama]" value="" /></td> </tr> </table>

the links have .hata-ekle class, increasing value of hidden input , span next it.

if there needed new row, user should click "add row" link , new cloned .montaj table should appear --number-- should replaced unique number.

how can this?

thanks...

ok,

i don't understand whole process can give pointers :

first method : write function taking needed number in parameter , creating table jquery utilities :

function addtable(number) { var table = $('<table>'); var tr = $('<tr>').appendto(table); var td = $('<td>').appendto(tr); var span = $('<span>').appendto(td).addclass('terminal_hatasi'+number) ... }

second method : clone table , search input/span , retag :

function addtable(number) { var clone = $('table.montaj').first().clone(); clone.find('input').each(function(item){ var name = $(this).attr('name'); $(this).attr('name',name.replace(/\d/,number)); }); ... $(body).append(clone); }

i think there more approach, these 2 came first mind. these not betters...

jquery replace

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -