473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

very simple form onchange - calculate qty*price, display price

I had this funtion working by using the onsumbit, but now I have to change it so that it will display the total price after changing the quanity amount.

Simple I know, but right now i can not get it to work.

thankful for any help.

cheers.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.  
  3.     function checkQuantity(frm) {
  4.         var succesful = false;
  5.         var numQuantity;
  6.         numQuantity = parseInt(frm.Quantity.value);
  7.         var numTotalPrice;
  8.  
  9.         if (numQuantity != 0) {
  10.             numTotalPrice = numQuantity * 4;
  11.             frm.TotalPrice.value = numTotalPrice; //new String(numTotalPrice);
  12.             successful = true;
  13.         }
  14.         else {
  15.             alert("Sorry must order more than 0");
  16.             successful = false;
  17.         }
  18.         return succesful;
  19.     }
  20.  
  21.  
  22. </script>
  23.  
  24.  
  25. <form action=""  onsubmit="return checkQuantity(this)" style="width: 193px">
  26.  
  27.                     <table cellpadding="4" style="width:111%">
  28.                         <tr>
  29.                             <td class="style1">
  30.                                 Quanity:</td>
  31.                             <td class="formInputCell">
  32.                                 <input name="Quantity" type="text" style="width: 55px" /></td>
  33.                         </tr>
  34.                         <tr>
  35.                             <td class="style1">
  36.                                 Total Price $
  37.                             </td>
  38.                             <td class="formInputCell">
  39.                                 <input name="TotalPrice" type="text" style="width: 55px" /></td>
  40.                         </tr>
  41.                         <tr>
  42.                         <td class="style2"></td>
  43.                         <td><input id="Submit1" type="submit" 
  44.                         value="Buy Now" class="buttonstyle" /></td>
  45.                         </tr>  
  46.                     </table>    
  47.                     </form>
  48.  
Mar 21 '10 #1
2 4230
gits
5,390 Expert Mod 4TB
just move the function call to a onchange handler of the corresponding input-node and pass the reference to the form to it ... you might even retrieve the form within the function ... as you like :)

kind regards
Mar 21 '10 #2
thanks so much I followed your advice.
Mar 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: tamorrel | last post by:
I am new to VB.Net and I'm creating an application that uses Windows Forms in a MDI parent. Typical Client/Server Application. I first create the layout of the form then write the code. If I close...
5
by: Mark 123 | last post by:
Hi I have a form with the input fields: ProductName Quantity and output fields: ProductPrice
0
by: BobbyChat | last post by:
Is there a way to display more than one record at a time on a popup form? I have a main form that has a button that triggers a popup form that is a continuous form. I am trying to get it to display...
1
by: Robert | last post by:
Need some help with this please. Is there a way to display more than one record at a time on a popup form? I have a main form that has a button that triggers a popup form that is a continuous...
1
by: Johnfcf | last post by:
I have a database consisting of 3 tables, the main table with main contact info, a second table with additional address info and a third table consisting of additional contact information, or more...
6
by: dale zhang | last post by:
Hi, I build a web form with a 4-cell table on the top (flawlayout), followed by some labels and textboxes (gridlayout). The web form is displayed well in dell m60 laptop with all resolution...
0
by: simon | last post by:
hello, relatively new to .net, i'm using vb.net and the 2.0 .net platform I'm trying to display a grid that has a text box on the left in one cell (with a hidden ID), which will be associated...
3
by: gator6688 | last post by:
I have to write a program that asks for a cost-per-item, number of items purchased, and a discount rate. Then it should calculate the total cost, tax due, and amount due. I have to use the...
1
by: ewart strain | last post by:
Hello all, I have a form thats tied to my access database and all seems to work well except for one small thing. Info on the code: whenever a consultant contract ends they get moved to an...
1
by: William Gill | last post by:
I hope I can state this clearly enough. I am redoing some of my html(php) forms. I'm trying to break things into three functions on a self processing php page: 1) show the form (and populate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.