Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems in passing array of variables

Status
Not open for further replies.

misslois74

Programmer
Sep 27, 2008
63
PH
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:

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.'&nbsp;&nbsp;&nbsp;<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;">&nbsp;&nbsp;&nbsp;&nbsp;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>
 
im at lost on how will i be able to get the values that the user entered on specific textboxes ... passed it to a php script and eventually store it in a database

That would all be something you'd ask in forum434 . Your JS looks like it's finished.

The only thing I'd say is that you shouldn't rely on JS to update the subtotals... do this server-side anyway as a precaution for those with JS disabled.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
my question actually lies on how will i be able to capture the values stored in textboxes will i do it in php is that what your saying?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top