misslois74
Programmer
im currently having problems in the current page im working, im at lost on how will i be able to get the values that the user entered on specific textboxes which is part of the array that was defined on the javascript passed it to a php script and eventually store it in a database, any idea on how will i go about it...
here is the code:
here is the code:
Code:
<script type="text/javascript">
function disen(c) {
var otd=c.parentNode;
var otr=otd.parentNode;
for (var j=1;j<otr.cells.length;j++) {
if (!c.checked) {
otr.cells[j].getElementsByTagName("input")[0].value="";
}
otr.cells[j].getElementsByTagName("input")[0].disabled=!c.checked;
}
}
function doit() {
var otbl=document.getElementById("tblid");
var sum, cv, nrow, ncell;
for (var i=1;i<otbl.rows.length-1;i++) {
sum=0;
ncell=otbl.rows[i].cells.length-1;
if (otbl.rows[i].cells[0].getElementsByTagName("input")[0].checked) {
for (var j=1;j<ncell;j++) {
cv=otbl.rows[i].cells[j].getElementsByTagName("input")[0].value;
if (cv.length==0||!/^\s*[+-]?\d*(\.\d*)?\s*$/.test(cv)) {
otbl.rows[i].cells[j].getElementsByTagName("input")[0].value="";
cv=0;
}
sum+=parseFloat(cv);
}
otbl.rows[i].cells[ncell].getElementsByTagName("input")[0].disabled=false;
otbl.rows[i].cells[ncell].getElementsByTagName("input")[0].value=sum;
}
}
nrow=otbl.rows.length-1; //last row
ncell=otbl.rows[nrow].cells.length-1; //last row's last cell
for (var j=1;j<otbl.rows[nrow].cells.length;j++) {
sum=0
for (var i=1;i<otbl.rows.length-1;i++) {
cv=otbl.rows[i].cells[j].getElementsByTagName("input")[0].value;
if (cv.length==0||!/^\s*[+-]?\d*(\.\d*)?\s*$/.test(cv)) {
otbl.rows[i].cells[j].getElementsByTagName("input")[0].value="";
cv=0;
}
sum+=parseFloat(cv);
}
otbl.rows[nrow].cells[j].getElementsByTagName("input")[0].value=sum;
//var s = sum;
//self.location='checkbox_sample2.php?meal_value=' + s;
}
document.valuemeal.sumresult.value=sum;
document.valuemeal.submit();
}
</script>
</head>
<body>
<table border=0 cellpadding=1 cellspacing=5 id="tblid"> <!-- I add an id to facilitate the referencing. -->
<tr>
<th>Days of Month</th>
<th>Kids</th>
<th>Adults</th>
<th>Volunteers</th>
<th>subtotal</th> <!-- added column -->
</tr>
<?php
for($i=1;$i<=31;$i=$i+1)
{
echo '<tr>
<td>'.$i.' <input type="checkbox" onclick="disen(this)"></td>
<td><input type="text" disabled="disabled" size=5 ></td>
<td><input type="text" disabled="disabled" size=5 ></td>
<td><input type="text" disabled="disabled" size=5 ></td>
<td><input type="text" disabled="disabled" size="5" readonly="readonly" /></td>
</tr>';
}
?>
<form action="process_checkbox_sample2.php" method=POST name="valuemeal">
<input type=hidden name="sumresult">
</form>
<tr>
<td><span style="font-weight:bold;"> subtotal:</span></td>
<td><input type="text" size="5" readonly="true" /></td>
<td><input type="text" size="5" readonly="true" /></td>
<td><input type="text" size="5" readonly="true" /></td>
<td><input name="subtotal" type="text" size="5" readonly="true" /></td>
</tr>
</table>
<button onclick="doit()">update subtotals</button><br />
<?php //$meal_value = $_POST['subtotal'];
//echo $meal_value; ?>
</body>
</html>