This is a simple problem. I am working on a PHP project related to customers and vendors. When I select customerid
from the database, unpaid bills of that customer populate automatically in a table, so table contains a check, the bill number, the bill amount, the paid amount, and a "remove" column.
This remove link will remove that row, so that I can pay only for some bills. (If I have 5 unpaid bills, I could remove 3 bills and enter the data for the other 2 bills). Here I want to show billno
and billamount
as labels, and the payment amount as a textbox for entering the amount. I need to post the billno
to the server because I may remove some rows. But $_POST
of PHP doesn't recognize a label. I tried with a td
id (table cell id) and input type "hidden" but that didn't work. Can you suggest a way to do this?
Here is my code:
Table code:
<TABLE id="mytable1">
<tr>
<th>Select</th>
<th>Bill No</th>
<th>Bill Amount</th>
<th>Received Amount</th>
<th>Remove</th>
</tr>
<TR>
<td ><INPUT type="checkbox" name="chk[]" ></td>
<td ><label id="labelidinv"></label><input type="hidden" name="invhide[]" value="12" ></td>
<TD><label id="labelidinvamt"></label> </TD>
<TD><input name="receivedamt[]" type="text" size="6" id="receivedamt" ></TD>
<td> <a href="#" onClick="deleteRowReceipt('mytable1')">Remove </a> </td>
</TR>
</table>
Ajax code:
var inv_id = xmlDoc.getElementsByTagName("inv_id");
var inv_amt = xmlDoc.getElementsByTagName("inv_amt");
var count = xmlDoc.getElementsByTagName("count");
var inv_id_desc = inv_id[0].firstChild.nodeValue;
var inv_amt_desc = inv_amt[0].firstChild.nodeValue;
var countdesc = count[0].firstChild.nodeValue;
document.getElementById('labelidinv').innerHTML =inv_id_desc;
document.getElementById('labelidinvamt').innerHTML=inv_amt_desc;
var table = document.getElementById('mytable1');
for(var j=1;j<countdesc;j++)
{
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++)
{
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
if(i==1)
newcell.innerHTML = inv_id[j].firstChild.nodeValue;
if(i==2)
newcell.innerHTML= inv_amt[j].firstChild.nodeValue;
}
}
Here I am not able to post label id values. Is there any way to do it like that? I want the read only values in labels, and I need to post them back to server. Thanks in advance.
Edit
I am sending ajax request like this
var custname = document.getElementById('customer').options[document.getElementById('customer').selectedIndex].value;
xmlhttp.open("POST","../MODEL/AjaxRequestHandler.php?action=custdetails&CUST_NAME="+custname,true)
At AjaxRequestHandler page:
$CUST_NAME = $_GET['CUST_NAME'];
$querry1 = "select * from RECEIVABLES where CUSTOMER_NAME = $cust_name and FULL_PART_PAID !='F' and voucher_type='SI' ";
/*full_part_paid column is whether that bill fully paid or not, and voucher type = "Sales invoice"*/
$res1 = odbc_exec($conn,$querry1);
$i = 0;
echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
echo '<XmlResponse>'. "\n";
while(odbc_fetch_row($res1))
{
$inv_id= odbc_result($res1, "invoice_id");
echo '<inv_id>'.$inv_id.'</inv_id>'. "\n";
$inv_amt = odbc_result($res1,"invoice_amount");
echo '<inv_amt>'.$inv_amt.'</inv_amt>'. "\n";
$i++;
}
echo '<count>'.$i.'</count>'."\n";
echo '</XmlResponse>'. "\n";