Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Performing text field calculations on a webpage

Status
Not open for further replies.

limitup77

IS-IT--Management
Jun 9, 2003
41
GB
Hi and thank you very much to anyone who can help with this. I'm very new to html, so please bear with me.

I have a form with an input field [Width] set to take cms.

I have three other input fields [productcode], Quantity and [cost]

I want to run a calculation where if the width is between
50-100cms the [productcode] field will be set to 2 and the [cost] field to 140.

If the width is between 100 and 150 the [Productcode] will be set to 3 and the [cost] field to 165.

I then need to multiple the [cost] field by the [quantity] field.

I've looked at various sites and links about this but got totally confused. I don't have a database running in the background, I simply want the fields to be displayed on the webpage. Can anyone either a) help me with the solution b) point me in the direction of a very easy beginners expressions link where I can learn to do it.

Thank you very much

RichD



 
b) point me in the direction of a very easy beginners expressions link where I can learn to do it.

What you are wanting to do will require a scripting language (VBScript or Javascript).

I prefer Javascript, IMO it's easier to learn.

Here's a link to a very good site to get you started:


[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
You have 2 options for this either use Javascript to perform the calculations on the fly and display thme in the form fields. Or use a Server-side language which would require you to submit the data in the form, do the calculations, and then redisplay the form with the results.

Which one is best for you depends on what is available to you, and where this is to be used.

If its to be used in a company where you can be sure every user will have Javascript enabled, then it would be a viable option.

However if it were to be deployed on the Internet, and you cannot be certain if everybody will have Javascript enabled, then maybe a server side solution may work for you.

Which server-side language to use depends on what is available. be it PHP,ASP or something else.

If you tell us which of these scenarios applies to you, we may be able to help you further.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks guys, as it's going onto the internet, a server side script would be better, I guess PHP.. have you any good education links or solution pages? Thanks again, RD
 
For Starters I'd like to point you to the PHP forum: forum434
As that will most likely solve any PHP issues you might encounter while developing this.

Now as for guides try this one from the famed w3schools.
This should get you started. If you have an specific questions, I'm sure the folks over at the PHP forum (including myself) will be happy to lend you a hand there.

PHP Forum: forum434

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Decided to go with javavscript as it seems to be easier??!

So far I have this: Yet I can't work out how to write the answers to the field [Answer]...or if the variable is correct.

Can anyone help? Thanks in advance

<SCRIPT LANGUAGE="JavaScript">


function Calculate(form){
var Answer

if(width >= 1 && width <= 110){
Answer = "1"
}
if(width >= 111 && width <= 160){
Answer = "1.5"
}
if (width >=161 && width <= 200){
Answer = "2"
}
if (width >=201 && width <= 240){
Answer = "2.5"
}
if (width >=241 && width <= 280){
Answer = "3"
}
// end of JavaScript functions -->
</SCRIPT>
</HEAD>

<BODY>

<P><FONT SIZE="+2">Simple Adder</FONT></P>

<FORM NAME="Calculator" METHOD="post">
<P>Enter a number: <INPUT NAME="width" TYPE=TEXT id="width" SIZE=10>
</P>
<P>
<INPUT TYPE="button" VALUE="Calculate" name="ClearButton" onClick="Calculate(this.form)">
</P>
<P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
</FORM>

</BODY>
</HTML>
 
Please direct the question to the javascript forum (forum216) if this is the method you have decided to use.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top