Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 6
Trades: 0
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
 
 
Register now for full access!
Old 10-03-2005, 01:52 AM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
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
Trades: 0
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
Trades: 0
Simplest calculation script I can think of:
Code:
<input type="text" onblur="alert(eval(this.value));" />
__________________

Please login or register to view this content. Registration is FREE
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 10-03-2005, 09:55 AM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.30957 seconds with 12 queries