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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maths In Java

Status
Not open for further replies.

stevenr

Technical User
Feb 21, 2001
89
GB
I'm trying to create a simple mathematical code using Javascript. What i want to do is have a text box which people can insert a number into, then press calculate and get a result.

e.g Hidden price in code of 1.99, on webpage user says i would like 2, then they press calculate and a total appears at the bottom of the screen.

Any ideas would be appreciated, i would prefer not to use cgi-scripts.

Cheers

Steve
 
This may help

<HTML>

<HEAD>
<TITLE>Exercise 5.3</TITLE>

<SCRIPT>
<!-- HIDE FROM OTHER BROWSERS

function calculate(form) {

form.twice.value = form.entry.value * 2;
form.square.value = form.entry.value * form.entry.value;

}

// STOP HIDING FROM OTHER BROWSERS -->
</SCRIPT>

</HEAD>

<BODY>

<FORM METHOD=POST>

Value: <INPUT TYPE=text NAME=&quot;entry&quot; VALUE=0
onChange=&quot;calculate(this.form);&quot;>
<BR>
Double: <INPUT TYPE=text NAME=&quot;twice&quot; VALUE=0
onChange=&quot;this.form.entry.value = this.value / 2;
calculate(this.form);&quot;>
<BR>
Square: <INPUT TYPE=text NAME=&quot;square&quot; VALUE=0
onChange=&quot;this.form.entry.value = Math.sqrt(this.value);
calculate(this.form);&quot;>

</FORM>

</BODY>

</HTML>
 
Thanks, i'm a bit nearer to my target now, basically i have an order form and wish to have a total price at the bottom of the page that updates when they put their quantities in.

Cheers

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top