任何人都可以请帮我算一个使用JavaScript的动态生成HTML表格的行数吗?如果任何人都可以在此帮助让我知道,我已经试图动态生成行的数据插入到数据库如何计算动态生成的html表中的行数?
我JS代码:
var count=1;
function addRow(tableID) {
/*if(empty(index))
{
var index = 0;
}
else
{
index++;
alert(index);
document.getElementById('cat').name = 'cat'+index;
}*/
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var count = rowCount-1;
alert(rowCount);
var selectOFCat = $("#"+tableID).find('tr:eq(0)').find('.cat').get(0);
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
$(table).find("tr:eq("+rowCount+")").find('.cat').attr("id","cat"+rowCount);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
function changeSelection(value){
var length = document.getElementById("ind").options.length;
if(value == "All"){
for(var i = 1;i
document.getElementById("ind").options[i].selected = "selected";
document.getElementById("ind").options[0].selected = "";
}
}
我的PHP代码:
Add your Products | |||||||||
| |||||||||
| |||||||||
<?php echo tep_draw_button(IMAGE_BUTTON_PRODINFO, 'person', null, 'primary',array('params' => 'name="add_pro" class="btn btn-danger" ')); ?> |
if(isset($_POST['add_pro']))
{
foreach($html->find('dataTable') as $table){
$all_trs = $table->find('tr');
$count = count($all_trs);
echo $count;
exit;
}
$src = $_POST['source'];
$products_source = implode(",", $src);
$opt = $_POST['option'];
$products_options = implode(",", $opt);
$products_array = array(
'products_quantity' => $products_quantity,
'products_date_added' => 'now()',
'products_source' => $products_source,
'products_frequency' => $products_frequency,
'products_options' => $products_options,
'products_unit' => $products_unit,
'customers_id' => $customer_id
);
tep_db_perform(TABLE_PRODUCTS, $products_array);
$products_desc_array = array(
'products_name' => $products_name,
'products_description' => $products_description
);
tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $products_desc_array);
$prod_id = tep_db_insert_id();
$category_id_array = array('products_id' => $prod_id,
'categories_id' => $category_type_id);
tep_db_perform(TABLE_PRODUCTS_TO_CATEGORIES, $category_id_array);
$update_stage = tep_db_query("update " . TABLE_CUSTOMERS . " set customers_stage='5' where customers_id = '" . $customer_id. "'");
tep_redirect(tep_href_link(FILENAME_REGISTRATION_6, '', 'SSL'));
}
?>
我想插入行中的值在动态生成的窗体中。
+0
清楚地陈述你的问题,用你尝试的一些适当的代码,并为你的问题添加适当的标签......! –
+1
为什么这个标签为“php”? –
+1
你还尝试过什么吗? –