Jump to content

JavaScript Form Update


stublackett

Recommended Posts

Hi Guys,

 

I've got a purchase system setup on my website... Theres a box titled "quantity" all I want to do is update the total as per the quantity amount.. We charge £45 for the product, So if 1 was entered, Obviously the script would need to do X * 45.

 

Never really touched JavaScript before, so any help / pointers would be appreciated.

 

Example form is @ : http://www.stuartblackett.com/order.php

 

All I want it to do is work out the "Quantity" in the box, Then * 45.. I can do the PHP stuff to calculate the rest, Its just the Java I need.. Possibly AJAX, I dunno hopefully you guys can tell me

Link to comment
https://forums.phpfreaks.com/topic/174679-javascript-form-update/
Share on other sites

Just an update...

 

I've found a script somewhere, Tried playing about with it.

 

Hopefully along the right lines.......

 

<html>
<head>
<script type="text/javascript">
function UpdateQuantity()  {
   this.form.total.value = this.form.quantity * 45;
}
document.onkeydown=UpdateQuantity;
</script>
</head>
<body>
<form name="form" method="post" >
Quantity:<br />
   <input name="quantity" onfocus="UpdateQuantity();" onkeydown="UpdateQuantity();" type="text" />
   <br />
   Cost: <input name="total" type="text" value="0" size="5" />
</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.