PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have an order form I am trying to get to auto calculate the total sales price based on quantity. I am trying to use a javascript function to calculate the total priced based on the quantity entered.
I have this in [syntax="html"]
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Order Page - Bloodlines of the Legends</title>
<script>
function total()
{
var qty= document.form1.quantity.value;
var price=document.form1.price.value;
var total=qty*pxeach;
document.form1.totalprice.value=total;
}
</script>
</head>
echo "<p align='center'>Quantity <input type='text' name='quantity' size='20' value=$quantity_ordered></p>";
/* I seed $quantity_ordered with a default value of 1 */
echo "<p align='center'> Price Each<input type='text' name='pxeach' size='20' value=$price_each></p>";
/* I pass the price each with the form that calls this form */
echo "<p align='center'>Total <input type='text' name='totalprice' size='20' onFocus='total()' value=$total_price ></p>";
The "onFocus='total()' isn't changing my total price. I know I'm missing something, could someone please point me in the right direction.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
The event only fires when focus is brought to that form field. Do you have Firebug for Firefox installed on your machine. Or the Web Developer extension? Both would give you detailed information as to what is happening in the javascript calls.
function total()
{
var qty= document.form1.quantity.value; // This exists in the form
var price=document.form1.price.value; // This however, doesn't. There is not field names price
var total=qty*pxeach; // You are now multiplying with a null value
document.form1.totalprice.value=total;
}
It was the varialbe names....thanks to everyone who replied....
It also dawned on me after I got it to work, that all I really had to do was add a field to the page that called the order form and I could skip a step....oh well,