473,805 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple price x quantity

Hi

I have a form with the input fields:

ProductName
Quantity

and output fields:

ProductPrice
TotalUSD

Here's what I want it to do:

a) After either the ProductName or Quantity fields are updated by the user,
I want the resulting calculation to be displayed for the Product Price and
the TotalUSD. The ProductName is a drop-down with the product name as the
description and the value the dollar amount of each product.

b) I want the output fields to be displayed as $ format.

c) I want it so that the output fields can't be manually overwritten by the
user and later the form will be posted to a database.

I began with the following but are not familiar with the syntax of
JavaScript and got syntax errors. I also need the syntax for the AfterUpdate
event for the two input fields. Can you help?

I think I'll name the form "Form1".

<SCRIPT LANGUAGE="JavaS cript">
Function CalculateTotal( form) {
form.ProductPri ce.value=(form. ProductName.val ue);
form.TotalUSD.v alue= (form.ProductNa me.value * form.Quantity.v alue)
}
</SCRIPT>
Jul 23 '05 #1
5 4694
Mark 123 wrote:
Hi

I have a form with the input fields:

ProductName
Quantity

and output fields:

ProductPrice
TotalUSD

Here's what I want it to do:

a) After either the ProductName or Quantity fields are updated by the user,
I want the resulting calculation to be displayed for the Product Price and
the TotalUSD. The ProductName is a drop-down with the product name as the
description and the value the dollar amount of each product.

b) I want the output fields to be displayed as $ format.

c) I want it so that the output fields can't be manually overwritten by the
user and later the form will be posted to a database.

I began with the following but are not familiar with the syntax of
JavaScript and got syntax errors. I also need the syntax for the AfterUpdate
event for the two input fields. Can you help?
There is no "AfterUpdat e" event. You want the onChange event.

onchange="Calcu lateTotal(this. form)"
I think I'll name the form "Form1".

<SCRIPT LANGUAGE="JavaS cript">
<script type="text"/javascript">
Function CalculateTotal( form) {
There is your syntax error, its function, not Function. Case Matters.
form.ProductPri ce.value=(form. ProductName.val ue);
form.TotalUSD.v alue= (form.ProductNa me.value * form.Quantity.v alue)
Append the $ before setting the value, or better, as you set it.

"$" + (form.ProductNa me.value * form.Quantity.v alue)
}
</SCRIPT>


--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Thanks. Regarding the currency, what if the multiplication causes greater
(or less) than 2 decimal places?


"Randy Webb" <Hi************ @aol.com> wrote in message
news:cp******** ************@co mcast.com...
Mark 123 wrote:
Hi

I have a form with the input fields:

ProductName
Quantity

and output fields:

ProductPrice
TotalUSD

Here's what I want it to do:

a) After either the ProductName or Quantity fields are updated by the user, I want the resulting calculation to be displayed for the Product Price and the TotalUSD. The ProductName is a drop-down with the product name as the description and the value the dollar amount of each product.

b) I want the output fields to be displayed as $ format.

c) I want it so that the output fields can't be manually overwritten by the user and later the form will be posted to a database.

I began with the following but are not familiar with the syntax of
JavaScript and got syntax errors. I also need the syntax for the AfterUpdate event for the two input fields. Can you help?


There is no "AfterUpdat e" event. You want the onChange event.

onchange="Calcu lateTotal(this. form)"
I think I'll name the form "Form1".

<SCRIPT LANGUAGE="JavaS cript">


<script type="text"/javascript">
Function CalculateTotal( form) {


There is your syntax error, its function, not Function. Case Matters.
form.ProductPri ce.value=(form. ProductName.val ue);
form.TotalUSD.v alue= (form.ProductNa me.value * form.Quantity.v alue)


Append the $ before setting the value, or better, as you set it.

"$" + (form.ProductNa me.value * form.Quantity.v alue)
}
</SCRIPT>


--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #3
I can't get that event to fire:

http://www.orbisoft.com/promo/doubleoffer_new.aspx
"Randy Webb" <Hi************ @aol.com> wrote in message
news:cp******** ************@co mcast.com...
Mark 123 wrote:
Hi

I have a form with the input fields:

ProductName
Quantity

and output fields:

ProductPrice
TotalUSD

Here's what I want it to do:

a) After either the ProductName or Quantity fields are updated by the user, I want the resulting calculation to be displayed for the Product Price and the TotalUSD. The ProductName is a drop-down with the product name as the description and the value the dollar amount of each product.

b) I want the output fields to be displayed as $ format.

c) I want it so that the output fields can't be manually overwritten by the user and later the form will be posted to a database.

I began with the following but are not familiar with the syntax of
JavaScript and got syntax errors. I also need the syntax for the AfterUpdate event for the two input fields. Can you help?


There is no "AfterUpdat e" event. You want the onChange event.

onchange="Calcu lateTotal(this. form)"
I think I'll name the form "Form1".

<SCRIPT LANGUAGE="JavaS cript">


<script type="text"/javascript">
Function CalculateTotal( form) {


There is your syntax error, its function, not Function. Case Matters.
form.ProductPri ce.value=(form. ProductName.val ue);
form.TotalUSD.v alue= (form.ProductNa me.value * form.Quantity.v alue)


Append the $ before setting the value, or better, as you set it.

"$" + (form.ProductNa me.value * form.Quantity.v alue)
}
</SCRIPT>


--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #4
Mark 123 wrote:
I can't get that event to fire:

http://www.orbisoft.com/promo/doubleoffer_new.aspx

<SCRIPT LANGUAGE="JavaS cript"<script type="text/javascript">


function CalculateTotal( form)

{
form.ProductPri ce.value=(form. ProductName.val ue);
form.TotalUSD.v alue= (form.ProductNa me.value * form.Quantity.v alue)
}

</SCRIPT>

That is a copy/paste. See the double script tags? Its throwing a syntax
error and then stops. Get rid of the extra script tag, and then validate
your HTML:
www.w3c.org

http://diveintomark.org/archives/200..._wont_help_you

While looking through that code, I noticed you are using onblur to
validate your fields. That unnecessary. Use the onChange, or the
onSubmit event handlers.

<input type="text" size="8" name="Quantity" class="textbx" tabindex="5"
onblur="check1( this.form1)" onchange="Calcu lateTotal(this. form)"
value="1">

onChange="check 1(this.form);Ca lculateTotal(th is.form)"

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
Mark 123 wrote:
Thanks. Regarding the currency, what if the multiplication causes greater
(or less) than 2 decimal places?


http://jibbering.com/faq/#FAQ4_6

And please don't top-post (That is also covered in the FAQ)

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1893
by: Ed | last post by:
Hoping someone an assist me urgently. I would truly appreciate and help. I have a form and prices are based on 'price break'. 1.The price break fields work fine, but I cannot for the life of me add more than one to a page. 2. Also need to add the two results to a 'total' field. (See code attached). Many thanks in advance.
1
3278
by: Shannan Casteel via AccessMonster.com | last post by:
If I had 2 tables, one that displayed ClaimNo, PartNo, and Quantity, and another that just has PartNo and Quantity, how could I get Access to search for the PartNo in table 2 that was entered in table 1, then if it found it add the associated quantity to table 2 from table 1, and if it is not found to add it, with its associated quantity to table 2. This should be simple.....its just a running total/tally.... Table 1 ClaimNo ...
2
1191
by: Erich93063 | last post by:
I am trying to query a table of items There is a field for the name of the item, price, quantity etc. When I query I would like to return a "total price" which would be price * quantity and alias it out as "Total". So something along the lines of: SELECT vchrItem, monPrice, intQuanity, (monPrice * intQuantity) AS Total, ...
5
2562
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"? I am so confused about this concept. please advise me. thank you.
24
6348
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
1
1515
by: menyki | last post by:
am writing a program to determine the best price that will attract maximum demand. first i had to generate random number to enable me determine the price and quantity demanded at the particular price. my problem is that the program has alot of errors. can u help me debug, please!!! i need it urgently. such error include unable to load include file stdio.h and so on. the source code is as shown below /* programe to solve mr jones problem....
8
36305
by: jimmyg123 | last post by:
Hi, I'm trying to do something similar. This is my javascript <script type='text/javascript'> function totalise(price,total) { var qty = window.document.getElementById('qty').value; var result = total; result.value = price * qty; }
2
1675
Stang02GT
by: Stang02GT | last post by:
Hello, I would just like to get your thoughts/ideas/suggestions on how I should go about createing a VERY SIMPLE purchasing system. A friend has asked me help him develop a simple purchasing database. Just off the top of my head this is what i have come up with for the table lay out. Tables = Bold Text Customer Name
12
2566
by: brossyg | last post by:
I have a very simple price times quantity calculation. The input is STWCORQuant: <input name="STWCORQuant" class="contactitalicbold" id="STWCORQuant" onChange="javascript:STWCORPrice();" value="0" size="8" style="text-align: right; font-family: ver"> And the fucntion is STWCORPrice(): <script language="javascript" type="text/javascript">
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.