Forum Moderators: open

Message Too Old, No Replies

Javascript +PHP

update totals for a php generated form

         

bbaker

6:50 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



first...I don't know jack about javascript

I have a form that is generated from php. I pulled the units, desc and price out of a MySQL db.

for the different input fields I have the id's as fielname[] since there are several fields to process on the php side of things. What I want is my javascript to update the subtotal[] fields onchange of the qty[] field.

Here's what the form looks like now: <snip>

Here's my PHP code:


<form name="MainForm">
<table width="600" align="center" border="0" cellpadding="4" cellspacing="1">
<?php
require('../dbconnect.inc');

$query = "SELECT * FROM price ORDER BY id ASC";
$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query");

while ($row = mysql_fetch_array($result)){
$id = $row['id'];
$desc = $row['desc'];
$unit = $row['unit'];
$price_bldr = $row['price_bldr'];
$price_home = $row['price_home'];
?>

<tr>
<td align="left"><input name="qty[]" id="qty[]" size="3" type="text" value="
<?
if ($desc == "Outside Corners (4 std.)"){
echo "4";
}
?>
" onChange="myCon()" /><input name="id[]" id="id[]"size="3" type="hidden" value="<? echo $id?>" />
</td>
<td><? echo $unit?></td>
<td><? echo $desc?></td>
<td align="right"><input name="price[]" id="price[]"size="3" type="hidden" value="<? echo $price_bldr?>" /><? echo "$".$price_bldr?></td>
<td align="right"><input name="subtotal[]" id="subtotal[]"size="7" type="text" /></td>
</tr>

<?php

}

?>
</form>

here's the js for the auto update i'm attempting:


<script type="text/javascript">
function myCon() {
document.MainForm.subtotal.value=document.MainForm.qty.value * document.MainForm.price.value
}
</script>

[edited by: Woz at 9:14 pm (utc) on Nov. 22, 2005]
[edit reason] No URLs plese, see TOS#13 [/edit]

bbaker

7:52 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Got it sovled....thanks though

coopster

8:04 pm on Nov 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Glad you got it, bbaker. Welcome to WebmasterWorld ;)