473,324 Members | 2,248 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,324 software developers and data experts.

calculation within a form

In my form, I have 4 objects that I want to work together:
<input name="price" type="text" id="price" value="100" size="4">

<input name="quantity" type="text" id="quantity" value="1" size="2">
<input name="shipping" type="radio" value="slow">

<input name="shipping" type="radio" value="fast">
<input name="total" type="text" id="total" size="8">
I 'd like that when someone checks the first radiobutton (slow),
the "total" textfield shows: price x quantity + 5

and when someone checks the second radiobutton (fast),
the "total" textfield shows: price x quantity + 10
Sadly, I don't know javascript, but there's got to be an easy way to do
that, right?

Thanks to all who will answer, any link to a page that has something
similar would also be appreciated.

Jul 20 '05 #1
6 1903
I would do it with onClick

<input name="shipping" type="radio" value="slow" onClick="...">

elji wrote:
In my form, I have 4 objects that I want to work together:
<input name="price" type="text" id="price" value="100" size="4">

<input name="quantity" type="text" id="quantity" value="1" size="2">
<input name="shipping" type="radio" value="slow">

<input name="shipping" type="radio" value="fast">
<input name="total" type="text" id="total" size="8">
I 'd like that when someone checks the first radiobutton (slow),
the "total" textfield shows: price x quantity + 5

and when someone checks the second radiobutton (fast),
the "total" textfield shows: price x quantity + 10
Sadly, I don't know javascript, but there's got to be an easy way to do
that, right?

Thanks to all who will answer, any link to a page that has something
similar would also be appreciated.


Jul 20 '05 #2
Lee
elji said:
<input name="price" type="text" id="price" value="100" size="4">
<input name="quantity" type="text" id="quantity" value="1" size="2">
<input name="shipping" type="radio" value="slow">
<input name="shipping" type="radio" value="fast">
<input name="total" type="text" id="total" size="8">

I 'd like that when someone checks the first radiobutton (slow),
the "total" textfield shows: price x quantity + 5

and when someone checks the second radiobutton (fast),
the "total" textfield shows: price x quantity + 10
Sadly, I don't know javascript, but there's got to be an easy way to do
that, right?


Is this for a class?
It seems too simplistic to be for a real website, and I'd hate
to think that somebody who doesn't know Javascript would try
to create a commercial web site. You could open yourself to
all sorts of legal and financial problems.

Jul 20 '05 #3
Lee wrote:
elji said:

<input name="price" type="text" id="price" value="100" size="4">
<input name="quantity" type="text" id="quantity" value="1" size="2">
<input name="shipping" type="radio" value="slow">
<input name="shipping" type="radio" value="fast">
<input name="total" type="text" id="total" size="8">

I 'd like that when someone checks the first radiobutton (slow),
the "total" textfield shows: price x quantity + 5

and when someone checks the second radiobutton (fast),
the "total" textfield shows: price x quantity + 10
Sadly, I don't know javascript, but there's got to be an easy way to do
that, right?

Is this for a class?
It seems too simplistic to be for a real website, and I'd hate
to think that somebody who doesn't know Javascript would try
to create a commercial web site. You could open yourself to
all sorts of legal and financial problems.

No, that's not for a class, this looks simplistic, but that's only a
part of a very large form, but I've only shown here where my problem is.

And yes, I hardly know javascript, but my commerce is not about programming.
Jul 20 '05 #4
Lee wrote:
Is this for a class?


What do you mean by `class'?
PointedEars
Jul 20 '05 #5
elji wrote:
<input name="price" type="text" id="price" value="100" size="4">
<input name="quantity" type="text" id="quantity" value="1" size="2">
<input name="shipping" type="radio" value="slow">
<input name="shipping" type="radio" value="fast">
<input name="total" type="text" id="total" size="8">

I 'd like that when someone checks the first radiobutton (slow),
the "total" textfield shows: price x quantity + 5
function calcTotal(o)
{
if (o
&& o.value
&& o.form
&& o.form.elements
&& o.form.elements['price']
&& o.form.elements['quantity']
&& o.form.elements['total'])
{
var total =
o.form.elements['price'].value * o.form.elements['quantity'].value;
var adds = {slow: 5, fast: 10};
total += (adds[o.value] ? adds[o.value] : 0);
o.form.elements['total'].value = total;
}
}
....
<input name="shipping" type="radio" value="slow"
onclick="calcTotal(this)">
and when someone checks the second radiobutton (fast),
the "total" textfield shows: price x quantity + 10
<input name="shipping" type="radio" value="fast"
onclick="calcTotal(this)">

The calcTotal(...) function decides what to add
depending on the `value' attribute of the radio
button. Untested.
Sadly, I don't know javascript,
But you can learn it.
but there's got to be an easy way to do that, right?


Yes, it is.
HTH

PointedEars
Jul 20 '05 #6
Thomas 'PointedEars' Lahn hu kiteb:
Lee wrote:
Is this for a class?


What do you mean by `class'?


Judging from context, I'd guess class as in a course of study.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #7

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

Similar topics

8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
2
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the...
1
by: cdelaney | last post by:
I have a form that I created a calculation on using 2003. The calculation works exactly like I want it to but ONLY on the first and last record. The calculation does not work/exist on records in...
0
by: gavo | last post by:
Hi. using A2K; i have a form containing a continous subform. The question is, how can i call a calculation for one of the fields in the continous subform from the main form. At the moment i...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
4
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
133
by: muhes | last post by:
Hello, I am working on a project for my department to design a form to calculate budgets. I really don't know much about access or programming in general. At this point, I am trying to design a...
5
kcdoell
by: kcdoell | last post by:
Hello: I thought I was done with this one but a user who is testing my DB just pointed out a problem. I used the following in the afterupdate event: Private Sub...
1
by: csolomon | last post by:
I have an unbound text box which I use to get a calculation, called DM_SampleWt. This text box's control source is: =GetSize(,Nz(,0),.!,.!.(2)) I have written a function that will get the required...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.