Salve ragazzi.
Ho trovato in rete lo script che riporto, che permette di clonare una riga di una tabella con tutto il suo contenuto.
Per ovvie ragioni, prendetelo con le pinzette, anche perchè io sono una capra in javascript ma purtroppo questo script mi serve.
Voglio precisare che script simili a questo ce ne sono tanti.
Avrei potuto prenderne uno da questo forum, invece a me serve proprio questo.
Ho anche visto che il sito di Xinod ne ha uno bellissimo ma purtroppo il suo script è lento rispetto a questo.
Questa premessa per dirvi che mi son dato da fare con le ricerche...
Vi riporto lo script:
Le parti del codice colorate, non vengono eseguite sotto internet explorer 8(che è quello su cui deve girare) mentre funzionano benissimo sotto Opera e Firefox.codice:<script language="javascript" type="text/javascript"> function add_new_row(tableid) { var theTable, theTableBody; theTable = (document.all) ? eval("document.all."+tableid) : eval("document.getElementById('"+tableid+"')"); theTableBody = theTable.tBodies[0]; // get Tbody Object theTabelBodyRow = theTableBody.rows; // get Tr Object theTabelBodyRowCell=theTabelBodyRow[0].cells; // get Td Object total_rows=theTabelBodyRow.length; no_of_insert = total_rows+1; if( total_rows < no_of_insert) { var newrow=theTabelBodyRow[total_rows-1].cloneNode(true); //the clone of the first row var createdRowCells = newrow.cells; for(i=0;i<createdRowCells.length;i++) { if(createdRowCells[i].id == 'serialno') createdRowCells[i].innerHTML = total_rows+1; } var inputElements = createdRowCells[i].getElementsByTagName("input"); for(cninput=0; cninput<inputElements.length; cninput++) { if(inputElements[cninput].type == 'text') { inputElements[cninput].value = ''; } if(inputElements[cninput].type == 'checkbox') { inputElements[cninput].checked = 'checked'; } if(inputElements[cninput].type == 'radio') { inputElements[cninput].checked = ''; } // if define with [ index_arr_sign = inputElements[cninput].id.lastIndexOf('['); if(index_arr_sign != '-1' ) { element_id = inputElements[cninput].id.substr(0,index_arr_sign); element_id = element_id+'['+total_rows+']'; str_element_name = inputElements[cninput].name.substr(0,inputElements[cninput].id.length); inputElements[cninput].id = element_id; inputElements[cninput].name = inputElements[cninput].name.replace(str_element_name, element_id); } // if define with _ index_arr_sign = inputElements[cninput].id.lastIndexOf('_'); if(index_arr_sign != '-1' ) { element_id = inputElements[cninput].id.substr(0,index_arr_sign); element_id = element_id+'_'+total_rows; str_element_name = inputElements[cninput].name.substr(0,inputElements[cninput].id.length); inputElements[cninput].id = element_id; inputElements[cninput].name = inputElements[cninput].name.replace(str_element_name, element_id); } } } theTableBody.appendChild(newrow); //appends the clone } } </script> Add New Row </p> <form name="form1" method="post" action=""> <table id="tbltest" align="center" class="display" cellpadding="0" cellspacing="0" border="0" width="100%" > <thead> <tr> <th>No</th> <th>Title</th> <th>Data</th> <th>Status</th> <th>action</th> </tr> </thead> <tbody> <tr> <td id="serialno" align="center" valign="middle">1</td> <td align="center" valign="middle">Mahesh</td> <td align="center" valign="middle"><input name="data_0" type="text" id="data_0"></td> <td align="center" valign="middle"><input type="checkbox" name="chkdata_0" id="chkdata_0" ></td> <td align="center" valign="middle">data13</td> </tr> </tbody> </table> <input type="submit" name="Submit" value="Submit"> </p> </form>
La parte blu non cicla la cella con id "serialno"
La parte rossa non modifica il nome del campo testo "data_0" in "data_(0..1..2..3..4..n)"
L'aranzione, infine, non imposta lo stato del campo "checkbox", su "checked"
Vi ringrazio anticipatamente se potreste farmi indicarmi come modificare opportunamente questo script.

Rispondi quotando