asked on
function addRow(divname) {
var totalrows = document.getElementById(divname).rows.length-2;
var newdiv = document.createElement('tr');
var products = '<?php echo $products; ?>';
newdiv.innerHTML = '<td>' + (totalrows + 1) + '</td>';
newdiv.innerHTML += '<td>' + products + '</td>';
document.getElementById(divname).appendChild(newdiv);
}
ASKER
ASKER
this is index.php
<?php
$title = "Invoicing Home";
$default1 = 'tabbertabdefault';
if (!include '../header2.inc')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include '../config/config.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include '../config/functions.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include '../config/mysql_connect.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include 'functions/main.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include 'functions/products.php')
{
echo 'Stop Error! 0x00000333';
die();
}
?>
<script type="text/javascript" src="script/add_row.js"></script>
<form action="tableaddrow_nw.html" method="get">
<center>
<table cellpadding="0" cellspacing="0" id="invoice">
<tr>
<td colspan="4"><center>Client: <?php clients(); ?></center></div></td>
</tr>
<tr>
<td>1</td>
<td><?php echo $pro; ?></td>
</tr>
<tr>
<td><div id="select"></div></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="1050" border="1">
<tr>
<td>
<p>
<input type="button" value="Add" onclick="addRow('invoice');" />
<input type="button" value="Remove" onclick="removeRowFromTable()" />
</p>
<td>
Total: <input type="text" name="tot" value="0">
</td>
</tr>
</table>
</center>
</form>
this is addrow.js
function addRow(divname) {
var totalrows = document.getElementById(divname).rows.length-2;
var newdiv = document.createElement('tr');
var products = '<?php echo `"Ok"`, $pro; ?>';
newdiv.innerHTML = '<td>' + (totalrows + 1) + '</td>';
newdiv.innerHTML += '<td>' + products + '</td>';
document.getElementById(divname).appendChild(newdiv);
}
ASKER
ASKER
<?php
$title = "Invoicing Home";
$default1 = 'tabbertabdefault';
if (!include '../header2.inc')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include '../config/config.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include '../config/functions.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include '../config/mysql_connect.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include 'functions/main.php')
{
echo 'Stop Error! 0x00000333';
die();
}
if (!include 'functions/products.php')
{
echo 'Stop Error! 0x00000333';
die();
}
?>
<script type="text/javascript">
function addRow(divname) {
var totalrows = document.getElementById(divname).rows.length-2;
var newdiv = document.createElement('tr');
var products = '<?php echo $pro; ?>';
newdiv.innerHTML = '<td>' + (totalrows + 1) + '</td>';
newdiv.innerHTML += '<td>' + products + '</td>';
document.getElementById(divname).appendChild(newdiv);
}
function removeRowFromTable()
{
var tbl = document.getElementById('invoice');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
</script>
<form action="tableaddrow_nw.html" method="get">
<center>
<table cellpadding="0" cellspacing="0" id="invoice">
<tr>
<td colspan="4"><center>Client: <?php clients(); ?></center></div></td>
</tr>
<tr>
<td>1</td>
<td><?php echo $pro; ?></td>
</tr>
<tr>
<td><div id="select"></div></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="1050" border="1">
<tr>
<td>
<p>
<input type="button" value="Add" onclick="addRow('invoice');" />
<input type="button" value="Remove" onclick="removeRowFromTable()" />
</p>
<td>
Total: <input type="text" name="tot" value="0">
</td>
</tr>
</table>
</center>
</form>
ASKER
ASKER
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY
If you want to add different products, you can:
1. use php function json_encode( ) to pass an array to javascript, if all the values are determined when loading.
2. use AJAX calls to get a new value from the server every time.