Welcome to WebmasterWorld Guest from 54.146.171.44

Forum Moderators: incrediBILL

Message Too Old, No Replies

Maths in HTML?

Can sums be done on a basic web page?

   
6:01 pm on Dec 23, 2003 (gmt 0)

10+ Year Member



I would like to allow visitors to my site to do some simple calculations. For example

Enter Number [text box]
multiply by: [text box]

[calculate Button]

Answer is: [answer displayed here]!

Hope you get the general idea!

Is their a method/formula for doing these sorts of sums?
If not what programs should i be using or learning?

I wrote a visual basic application a few years ago that does all the calculations that would be required in my field. I havent touched VB in years so i dont even know if that could be converted to go on the site?

Any help or advice greatly appreciated!

Thanks

6:03 pm on Dec 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pure HTML has no computational element to it; however you can build an extremely sophisticated calculator in HTML using JavaScript.

Plenty of examples on the web; try:

[google.com...]

If you have no experience of JavaScript it may be best to get into the basics of JavaScript first, in particular how you get and set form field values...

[edited by: dmorison at 6:04 pm (utc) on Dec. 23, 2003]

6:04 pm on Dec 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



VB executables can be run in certain web server environments, but you are much better off, using a scripting language such as JavaScript, PERL, or PHP, that is more geared for the web.

Just do a search for -> basic math scripts
and you will get plenty of information on implementing math functionality into your web site.

6:08 pm on Dec 23, 2003 (gmt 0)

10+ Year Member



Raw HTML cannot do such calculations. HTML makes pages look pretty, but that's about where it stops.

You're interested in some scripting. Server-side scripting requires support by the hosting server. This could be PHP, ASP, Perl, or any number of alternatives. Your visitors would enter the numbers & click the button which would post the figures back to the server. The server would serve up another page with the results.

An alternative is client-side scripting. I think this is what most online mortgage calculators I've seen are doing.

The browser loads a small script & runs it right there. This can be done in VBScript or Java ... probably some alternatives there too. But now that the browser is doing the work, you get into issues of which browsers support which constructs of which languages. Most modern browsers support Java, but there are differences in how they treat various aspects of it.

I think there's a Java forum here ... and you'd get more help there I suspect.

12:06 pm on Dec 24, 2003 (gmt 0)

10+ Year Member



Cheers for the replys, seems most of you reckon Java is the way to go.

I have no experience in java at all! but i guess you have got to start somewhere.

Thanks again

1:06 pm on Dec 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, CelticFC!

I have no experience in java at all! but i guess you have got to start somewhere.

I wrote a simple JS calculator (my first and only JS program) by looking at a couple of calculators and shamelessly stealing and modifying. Most programming languages are fairly similar, and a simple program in most languages is fairly understandable even by someone who has not used that language.

I used the w3schools tutorials to help me, found them moderately useful. Also asked many questions here when I got stuck!

A full JS book would have been overkill for my needs, but might be the way to go if you plan on doing more than that calculator.

<added>We now have a Javascript Forum [webmasterworld.com] where you can ask for advice.</added>

1:43 pm on Dec 24, 2003 (gmt 0)

10+ Year Member



Hi Mohamed

I think a book would probably be a bit of an overkill for me to. The calculations i want to do on the website is quite basic stuff. For example convert Litres to Gallons, PSI to BAR.

If i could find a basic script for this i think it would be easy to modify for other similar conversions.

I was thinking of making the program i made available for free download, but if i can get the conversions to run online it may help in keeping visitors coming back to my site.

1:59 pm on Dec 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have no experience in java at all! but i guess you have got to start somewhere.

My apologies if this is too basic, but make sure you are not confusing java with javascript (also known as js). Both have been mentioned here.

2:53 pm on Dec 24, 2003 (gmt 0)

10+ Year Member



If your calculation is complicated, maybe the best choice would be to search and download a script already created by someone else, but if it is simple, maybe itís preferable to create it on your own, in that way you will learn in the process, and probably then youíll realize that you can use JavaScript for many other things, it is by far the most used client side language on the web.

I started to learn JavaScript in www.quirksmode.org, so I would recommend to go there to begin with the basics of the language, very good resource i think.

11:37 am on Dec 26, 2003 (gmt 0)

10+ Year Member



Here's a page with conversion tables I use all the time. The calculations are done using JavaScript which is going to be the "easiest" resolution to your situation.

Click on the "Interactive Converters" page and then view source to get some ideas:

www.economatics.co.uk/industrial/conversiontables/

Good Luck

2:59 pm on Dec 26, 2003 (gmt 0)

10+ Year Member



Thanks Michael thats just the sort of calculations i needed.