Reply
how do I do calculations
Old 10-03-2005, 01:48 AM how do I do calculations
Novice Talker

Posts: 6
newbe question......How do I do calculations with several form fields on a webpage. Also, is there a program that will help me with it?...I have searched for answers and any help is much appriciated....Thanks
bayala13 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 10-03-2005, 01:52 AM
funkdaddu's Avatar
Web Design Snob

Posts: 636
Simple calculation:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
function calculate() {
	document.FormName.f3.value = parseInt(document.FormName.f1.value) + parseInt(document.FormName.f2.value);
	return false;
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="FormName" action="" method="get" name="FormName" onsubmit="return calculate();">
			<input type="text" name="f1" value="1" size="2"> + <input type="text" name="f2" value="2" size="2"> = <input type="text" name="f3" size="2"><br>
			<input type="submit" name="submitButtonName" value="Calculate Answer">
		</form>
		<p></p>
	</body>

</html>
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 10-03-2005, 01:58 AM
Novice Talker

Posts: 6
so I would create a form now and enter this code and work from there? I will need to name the fiels f1 f2 etc right?
bayala13 is offline
Reply With Quote
View Public Profile
 
Old 10-03-2005, 03:40 AM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Simplest calculation script I can think of:
Code:
<input type="text" onblur="alert(eval(this.value));" />
__________________
Free Teacher Websites
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 10-03-2005, 09:55 AM
funkdaddu's Avatar
Web Design Snob

Posts: 636
You can name the fields whatever you want, just make sure to reference them by their correct name in the function. Check out WebMonkey's Javascript Tutorial - it's how I learned JS.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Reply     « Reply to how do I do calculations
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12423 seconds with 12 queries