text box in form

T

Tony

Hi there
Is there a way to + or x the values in two text boxes?
For instance, lets say you have 3 text boxes in a form, can you, using frontpage 2003 forms, take the number or value in textbox1 + or x it to the value in textbox2 and have the results show up in textbox3. If so, How?
Thanks
 
J

Jim Buyens

-----Original Message-----
Hi there
Howdy.

Is there a way to + or x the values in two text boxes?
For instance, lets say you have 3 text boxes in a form,
can you, using frontpage 2003 forms, take the number or
value in textbox1 + or x it to the value in textbox2 and
have the results show up in textbox3. If so, How?

Suppose you have three text boxes named txtQty, txtPrc,
and txtTot. Add the following script to your <head>
section:

<script>
function calcTot(){
var nQty = parseFloat(document.forms[0].txtQty.value);
var nPrc = parseFloat(document.forms[0].txtPrc.value);
if (isNaN(nQty) || isNaN(nPrc)){
document.forms[0].txtTot.value="";
return;
}
document.forms[0].txtTot.value =nQty * nPrc;
}
</script>

adn then call the function every time the value of either
the txtQty or txtPrc text boxe changes. The code for the
three text boxes would then look like this.

<input type="text" name="txtQty" size="20"
onchange="calcTot();">

<input type="text" name="txtPrc" size="20"
onchange="calcTot();">

<input type="text" name="txtTot" size="20">

Keep in mind, though, that the Web visitor can turn off
JavaScript, or easily modify the code to produce
incorrect answers.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
T

Tony

Thanks you and just for fun I tried your code and it
works. You got me thinking about the user not necessarily
having javascript turned on, and so I decided that this
is not a good way to go...Thanks.
The problem is I am trying to make an easy order form for
a friend to put on his website and I cannot think of a
better way to do this...any ideas?


-----Original Message-----
-----Original Message-----
Hi there
Howdy.

Is there a way to + or x the values in two text boxes?
For instance, lets say you have 3 text boxes in a form,
can you, using frontpage 2003 forms, take the number or
value in textbox1 + or x it to the value in textbox2 and
have the results show up in textbox3. If so, How?

Suppose you have three text boxes named txtQty, txtPrc,
and txtTot. Add the following script to your <head>
section:

<script>
function calcTot(){
var nQty = parseFloat(document.forms[0].txtQty.value);
var nPrc = parseFloat(document.forms[0].txtPrc.value);
if (isNaN(nQty) || isNaN(nPrc)){
document.forms[0].txtTot.value="";
return;
}
document.forms[0].txtTot.value =nQty * nPrc;
}
</script>

adn then call the function every time the value of either
the txtQty or txtPrc text boxe changes. The code for the
three text boxes would then look like this.

<input type="text" name="txtQty" size="20"
onchange="calcTot();">

<input type="text" name="txtPrc" size="20"
onchange="calcTot();">

<input type="text" name="txtTot" size="20">

Keep in mind, though, that the Web visitor can turn off
JavaScript, or easily modify the code to produce
incorrect answers.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------

.
 
M

MD WebsUnlimited.com

Hi Tony,

You may wish to take a look at Form Calculator at
http://www.websunlimited.com/order/Product/FormCalc/formcalc.htm
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
----------------------------------------------------------------------------
--------------------
If you think I'm doing a good job, let MS know at (e-mail address removed)

Tony said:
Hi there
Is there a way to + or x the values in two text boxes?
For instance, lets say you have 3 text boxes in a form, can you, using
frontpage 2003 forms, take the number or value in textbox1 + or x it to the
value in textbox2 and have the results show up in textbox3. If so, How?
 
J

Jim Buyens

Tony said:
Thanks you and just for fun I tried your code and it
works. You got me thinking about the user not necessarily
having javascript turned on, and so I decided that this
is not a good way to go...Thanks.
The problem is I am trying to make an easy order form for
a friend to put on his website and I cannot think of a
better way to do this...any ideas?

I would recommend doing these calculations and then updating
the database, sending the mail, or whatever on the Web server.
This would be fairly easy to program in ASP or ASP.NET, for
example.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top