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

Calculating values in forms!

Status
Not open for further replies.

CooterBrown

IS-IT--Management
Aug 17, 2001
125
0
0
US
I'm not a Javascript programmer so if anyone can help me with this, Father Christmas shall be good to you this year.

I'm having my users fill out a form. Basically they are entering numeric data into the input boxes. I want to do some calculations on that data, basically add and subtract, and pass the value of the results on to an output page or if that is to difficult document.write the value on the same page.

I am sure one of you gurus is just dying to help a fella out on this miserable Monday morning.

Thanks in advance for any help and remember, Father Christmas loves you!
 
<!-- this is a basic thing but it shows you everything you need to do maths stuff -->

<html>
<head>
<script language=&quot;JavaScript&quot;>
function DoMaths(){
document.frm1.answer.value=parseInt(document.frm1.no1.value) + parseInt(document.frm1.no2.value);
}
</script>
</head>
<body>
<form name=&quot;frm1&quot;>
<input type=&quot;text&quot; name=&quot;no1&quot;><br>
<input type=&quot;text&quot; name=&quot;no2&quot;><br>
<input type=&quot;button&quot; Value=&quot;calculate&quot; onclick=&quot;DoMaths();&quot;><br>
<input type=&quot;text&quot; name=&quot;answer&quot;>
</form>
</body>
</html>

<!-- Tell Father Christmas I want a Girl Friend for XMAS -->
<!-- or 2 or 3 :) -->
 
Damian13
Thanks for the script but is there a way to pass the value to another page, say a results page?

Father Xmas does make gf's however I believe they are of the inflatable nature! I will see if he can spare an extra for you!
 
<html>
<head>
<script language=&quot;JavaScript&quot;>
function DoMathsPopup(){
document.frm1.answer.value=parseInt(document.frm1.no1.value) + parseInt(document.frm1.no2.value);

winpopup = window.open('','popup','height=500,width=400,menubar=no,scrollbars=no,status=no,toolbar=no,screenX=100,screenY=0,left=100,top=0');
winpopup.document.write('<HTML>\n<HEAD>\n');
winpopup.document.write('<TITLE>This is a popup</TITLE>\n');
winpopup.document.write('</HEAD>\n');
winpopup.document.write('<BODY>\n');
winpopup.document.write('<h1><marquee>'+ document.frm1.answer.value + '</marquee></h1>');

winpopup.document.write('<FORM NAME=&quot;FORM1&quot;>\n');

winpopup.document.write('<INPUT TYPE=&quot;BUTTON&quot; VALUE=&quot;Close Window&quot; ONCLICK=&quot;window.close();&quot;>\n');
winpopup.document.write('</FORM>\n');
winpopup.document.write('</BODY>\n</HTML>\n');

winpopup.document.close(); //Close the Window to additional writes

}
</script>
</head>
<body>
<form name=&quot;frm1&quot;>
<input type=&quot;text&quot; name=&quot;no1&quot;><br>
<input type=&quot;text&quot; name=&quot;no2&quot;><br>
<input type=&quot;button&quot; Value=&quot;calculate&quot; onclick=&quot;DoMathsPopup();&quot;><br>
<input type=&quot;hidden&quot; name=&quot;answer&quot;>
</form>
</body>
</html>

<!-- I would prefer a real girl friend thanks :) -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top