On the webpage I have a button (image link) that runs a javascript command to add a row to my table form.
Here is the applicant javascript:
Anyone see something I missed?
Thanks!
Jason
Code:
<a onClick="addRow(<%= @num_variants %>); return false;"><%= image_tag 'pages/classifieds/add-additional-row.png' %></a>
Here is the applicant javascript:
Code:
function addRow(fields) {
var targetTable = document.getElementById("listing_table");
var newRow = targetTable.insertRow(-1);
var tableRows = targetTable.getElementsByTagName("TR").length - 2;
//account for headings and example rows
var newCell = newRow.insertCell(0);
newCell.innerHTML = '<span class="red">*</span>'+tableRows;
for(i = 0; i < fields; i++) {
cell = i + 1;
var newCell = newRow.insertCell(cell);
newCell.innerHTML = '<input type="text" name="option['+tableRows+']['+i+']" id="option['+tableRows+']['+i+']" value="" />';
eval("option"+tableRows+""+i+"= new LiveValidation('option["+tableRows+"]["+i+"]')");
eval("option"+tableRows+""+i+".add( Validate.Presence )");
}
i = fields + 1;
var newCell = newRow.insertCell(i);
newCell.innerHTML = '<input id="quantity['+tableRows+']" name="quantity['+tableRows+']" type="text" class="split_text_quantity" value="" />';
i++;
var newCell = newRow.insertCell(i);
newCell.innerHTML = '$<input id="price_dollars['+tableRows+']" name="price_dollars['+tableRows+']" type="text" class="split_text_dollars" value="" />.<input id="price_cents['+tableRows+']" name="price_cents['+tableRows+']" type="text" class="split_text_cents" value="" /><a id="remove[\''+tableRows+'\']" href="#" onclick="removeRow(this.parentNode.parentNode.rowIndex,'+fields+');">[Remove]</a>';
//newCell.innerHTML = '$<input id="price_dollars['+tableRows+']" name="price_dollars['+tableRows+']" type="text" class="split_text_dollars" value="" />.<input id="price_cents['+tableRows+']" name="price_cents['+tableRows+']" type="text" class="split_text_cents" value="" /> <a href="#" onclick="this.parentNode.parentNode.parentNode.deleteRow( this.parentNode.parentNode.rowIndex );">[Remove]</a>';
i++;
eval("qty"+tableRows+" = new LiveValidation('quantity["+tableRows+"]');");
eval("qty"+tableRows+".add( Validate.Presence );");
eval("qty"+tableRows+".add( Validate.Numericality, { onlyInteger: true } );");
eval("price_d"+tableRows+"= new LiveValidation('price_dollars["+tableRows+"]', { insertAfterWhatNode: \"remove['"+tableRows+"']\" } );");
eval("price_c"+tableRows+"= new LiveValidation('price_cents["+tableRows+"]', { insertAfterWhatNode: \"remove['"+tableRows+"']\" } );");
eval("price_d"+tableRows+".add( Validate.Presence );");
eval("price_c"+tableRows+".add( Validate.Presence );");
eval("price_d"+tableRows+".add( Validate.Numericality, { onlyInteger: true } );");
eval("price_c"+tableRows+".add( Validate.Numericality, { onlyInteger: true } );");
}
Anyone see something I missed?
Thanks!
Jason