Use a form to do a calculation

  • Thread starter Thread starter Jane Here
  • Start date Start date
J

Jane Here

How can I use a FP2003 form to do a calculation?

Example: User enters these two fields on a form:
Number: 100
Multiply: 2.5

Now I want to display the answer: 250. How do I go about this?


BTW: I have these books on FrontPage but don't see where this sort of thing
is covered:
FrontPage 2003 Bible - Simmons and Micorosoft Office.
FrontPage 2003 - Buyens.

Any help to get me started will be appreciated.
 
Requires JavaScript, in IE Address bar do a search for:

? JavaScript Form Calculation Scripts

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
This is really a JavaScript technique and not a FrontPage feature.
That's why you don't find it in books about FrontPage.

The Web page at:

http://www.interlacken.com/tricks/trick09/coffeebk.htm

contains some code that does something like you describe. Perhaps you
can derive some inspiration from that.

Basically, if you have two text boxes named num and mult, you would
add this attribute to each one:

onchange="calcform();"

and then add a script like this to the <head> section:

<script>
function calcform(){
document.forms[0].ans.value = document.forms[0].num.value *
document.forms[0].mult.value;
}
</script>

where ans is the name of a third text box. However, you may need to
add some more code to make sure that both values you want to multiply
are numeric or blank, and to handle the situation where they aren't.

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)
|/---------------------------------------------------
*----------------------------------------------------
 
Thanks for the feedback.
*and for the book<g>


Jim Buyens said:
This is really a JavaScript technique and not a FrontPage feature.
That's why you don't find it in books about FrontPage.

The Web page at:

http://www.interlacken.com/tricks/trick09/coffeebk.htm

contains some code that does something like you describe. Perhaps you
can derive some inspiration from that.

Basically, if you have two text boxes named num and mult, you would
add this attribute to each one:

onchange="calcform();"

and then add a script like this to the <head> section:

<script>
function calcform(){
document.forms[0].ans.value = document.forms[0].num.value *
document.forms[0].mult.value;
}
</script>

where ans is the name of a third text box. However, you may need to
add some more code to make sure that both values you want to multiply
are numeric or blank, and to handle the situation where they aren't.

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)
|/---------------------------------------------------
*----------------------------------------------------


"Jane Here" <[email protected]> wrote in message
How can I use a FP2003 form to do a calculation?

Example: User enters these two fields on a form:
Number: 100
Multiply: 2.5

Now I want to display the answer: 250. How do I go about this?


BTW: I have these books on FrontPage but don't see where this sort of thing
is covered:
FrontPage 2003 Bible - Simmons and Micorosoft Office.
FrontPage 2003 - Buyens.

Any help to get me started will be appreciated.
 
If I want to add text to a field, do I need to do that in Java script as
well?


For example: I have a country drop down, and I want to use the country field
as the subject of the email sent by the form. I would like to add text to
it, some thing like "Request for data" + USA.

Can this be done without Java?




Jim Buyens said:
This is really a JavaScript technique and not a FrontPage feature.
That's why you don't find it in books about FrontPage.

The Web page at:

http://www.interlacken.com/tricks/trick09/coffeebk.htm

contains some code that does something like you describe. Perhaps you
can derive some inspiration from that.

Basically, if you have two text boxes named num and mult, you would
add this attribute to each one:

onchange="calcform();"

and then add a script like this to the <head> section:

<script>
function calcform(){
document.forms[0].ans.value = document.forms[0].num.value *
document.forms[0].mult.value;
}
</script>

where ans is the name of a third text box. However, you may need to
add some more code to make sure that both values you want to multiply
are numeric or blank, and to handle the situation where they aren't.

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)
|/---------------------------------------------------
*----------------------------------------------------


"Jane Here" <[email protected]> wrote in message
How can I use a FP2003 form to do a calculation?

Example: User enters these two fields on a form:
Number: 100
Multiply: 2.5

Now I want to display the answer: 250. How do I go about this?


BTW: I have these books on FrontPage but don't see where this sort of thing
is covered:
FrontPage 2003 Bible - Simmons and Micorosoft Office.
FrontPage 2003 - Buyens.

Any help to get me started will be appreciated.
 
Requires JavaScript, unless you are processing the form via ASP, ASP.net, PHP, etc. where you can
combine the content.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================


Jane Here said:
If I want to add text to a field, do I need to do that in Java script as
well?


For example: I have a country drop down, and I want to use the country field
as the subject of the email sent by the form. I would like to add text to
it, some thing like "Request for data" + USA.

Can this be done without Java?




Jim Buyens said:
This is really a JavaScript technique and not a FrontPage feature.
That's why you don't find it in books about FrontPage.

The Web page at:

http://www.interlacken.com/tricks/trick09/coffeebk.htm

contains some code that does something like you describe. Perhaps you
can derive some inspiration from that.

Basically, if you have two text boxes named num and mult, you would
add this attribute to each one:

onchange="calcform();"

and then add a script like this to the <head> section:

<script>
function calcform(){
document.forms[0].ans.value = document.forms[0].num.value *
document.forms[0].mult.value;
}
</script>

where ans is the name of a third text box. However, you may need to
add some more code to make sure that both values you want to multiply
are numeric or blank, and to handle the situation where they aren't.

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)
|/---------------------------------------------------
*----------------------------------------------------


"Jane Here" <[email protected]> wrote in message
How can I use a FP2003 form to do a calculation?

Example: User enters these two fields on a form:
Number: 100
Multiply: 2.5

Now I want to display the answer: 250. How do I go about this?


BTW: I have these books on FrontPage but don't see where this sort of thing
is covered:
FrontPage 2003 Bible - Simmons and Micorosoft Office.
FrontPage 2003 - Buyens.

Any help to get me started will be appreciated.
 

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

Back
Top