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



Closed Thread
I need a calculator (plug and play) stumped
Old 11-26-2009, 05:47 PM I need a calculator (plug and play) stumped
webspace's Avatar
Super Spam Talker

Posts: 933
Name: Buck Roberts
Location: Astoria, Oregon, United States
Trades: 0
I need a hand making a calculator for website I'm building for a physics class.

Basically. I calculates a persons walking speed by multiplying their body height in centimeters by .41 to get the person's stride length. Then multiplying that by 6582 (the average number of steps a person walks in an hour then divides that number by 100,000 to convert centimeters in to kilometers.

So basically you enter your height and it tells you how fast your average walking speed should be.

Equation:

H=height

.41(h)(6582)/100000=walking speed in km/h

Pretty simple math I just don't know how to put this into a webpage.

I just want a calculator looking form that a visitor can input their height in centimeters and get a walking speed in kilometers per hour.

Thanks for your help.

Here's the site I'm working on for my project. It's nothing special. Only for a presentation in my physics class.
http://decodingthefossilrecord.webs.com
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
blog about paintings, drawings and photographs.

Please login or register to view this content. Registration is FREE
Weapons system and aerospace components

Last edited by webspace; 11-26-2009 at 06:09 PM..
webspace is offline
View Public Profile Visit webspace's homepage!
 
 
Register now for full access!
Old 11-27-2009, 01:20 AM Re: I need a calculator (plug and play) stumped
webspace's Avatar
Super Spam Talker

Posts: 933
Name: Buck Roberts
Location: Astoria, Oregon, United States
Trades: 0
I have no idea what I'm doing here. I looked up some tutuorials. They all assume you know something about java script which I don't.

Code:
<script type="text/javascript">
var a = (6582*.41)/100000
document.write('a: ' * input);
</script> 

<form name="calc" action="#"><table align="center"
border="1"><tr><td align="right">height in cm: </td>
<td align="left"><input type="text" name="height in cm" size="5" />
</td></tr><tr><td colspan="2" align="center">
<input type="button" value="Calculate" onclick="speed();" /></td></tr>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
blog about paintings, drawings and photographs.

Please login or register to view this content. Registration is FREE
Weapons system and aerospace components
webspace is offline
View Public Profile Visit webspace's homepage!
 
Old 11-27-2009, 03:13 AM Re: I need a calculator (plug and play) stumped
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I'll not try and write a tutorial but ->
Code:
<script type="text/javascript">
	var c_km2mph = 0.62137; // constant for KPH to MPH
	var c_mph2km = 1.60934; // constant for MPH to KPH
	var c_Places = 4; // constant for number of decimal places
	
	var c_Converting = null;
	function setMode(which) {
		c_Converting = which;
	}
	
	function Calc() {
		switch (c_Converting) {
			case "mph":
				document.thisform.val.value = roundNumber(mph2km(document.thisform.inp.value),c_Places);
				document.getElementById('ret').innerHTML = "Kilometres per hour";
				break;
			case "kph":
				document.thisform.val.value = roundNumber(km2mph(document.thisform.inp.value),c_Places);
				document.getElementById('ret').innerHTML = "Miles per hour";
				break;
		}		
	}
	function roundNumber(p_Num, p_Places) { // Arguments: number to round, number of decimal places
	  return Math.round(p_Num*Math.pow(10,p_Places))/Math.pow(10,p_Places);
		}
	function mph2km(value) {
		return value * c_mph2km;
	}
	function km2mph(value) {
		return value * c_km2mph;
	}
</script>
HTML Code:
<form id="id" name="thisform">
	<input type="text" name="inp" value=""/> Input value to convert 
    <br />
	<input type="radio" name="conv" value="kph" onclick="setMode(this.value);" />KPH <input type="radio" name="conv" value="mph" onclick="setMode(this.value);" />MPH
    <br />
	Equals <input type="text" name="val" value=""/> <span id="ret"></span> 
    <br />
	<input type="button" name="convert" value="Convert" onclick="Calc();"/>
    <br />
</form>
Demonstration at ->
http://www.modtalk.co.uk/_site/code/...m-mph-convert/
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 11-27-2009, 03:27 AM Re: I need a calculator (plug and play) stumped
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, it's relatively simple, but if you don't have any experience, it's true than tutorials will be hard.

First, you need to have the user give you the height. The formula is simple enough and straightforward, and we need a container to display the result.

As I hate modal js popups, I will work with a form which will contain a text input and a button, and a span that will be updated with the result.

First, the html:
HTML Code:
<html>
    <body>
    <form>
        Your height, in centimeters:<input type="text" id="inpTxtH" name="inpTxtH" /> <input type="button" onclick="javascript:compute();" value="compute"/><br/>
        <span id="resultHolder"/>
    </form>
    </body>
</html>
I skipped doctype and all those details, but you get the idea.

Next, the javascript...
For that, we first need to have it get the value in the field.
For that, as I put an id attribute on the field, I can use a document.getElementById to locate it:
Code:
height=document.getElementById('inpTxtH').value
Then, computing the value:
Code:
speed=height*0.41*6582/100000
And now, we will put that result in the span container.
Here too, I will use the id to locate it, and rewrite the html contained in that element:
Code:
document.getElementById('resultHolder').innerHTML='Your average walking speed is '+speed+' Km per hours.'
And there you are...
Going a bit further, we can round on 2 decimals the result with this:
Code:
document.getElementById('resultHolder').innerHTML='Your average walking speed is '+Math.round(speed*100)/100+' Km per hours'
And even put a check to verify that only numbers are entered in the field:
Code:
            if(!isNaN(height)){
                speed=height*0.41*6582/100000
                document.getElementById('resultHolder').innerHTML='Your average walking speed is '+Math.round(speed*100)/100+' Km per hours'
            }else{
                document.getElementById('resultHolder').innerHTML='Please enter your height in centimeters, without any letters.'
            }
In the end, my resulting script will be:
HTML Code:
<html>
    <body>
        <script type="text/javascript">
        function compute(){
            height=document.getElementById('inpTxtH').value
            if(!isNaN(height)){
                speed=height*0.41*6582/100000
                document.getElementById('resultHolder').innerHTML='Your average walking speed is '+Math.round(speed*100)/100+' Km per hours'
            }else{
                document.getElementById('resultHolder').innerHTML='Please enter your height in centimeters, without any letters.'
            }
        }
        </script>
    <form>
        Your height, in centimeters:<input type="text" id="inpTxtH" name="inpTxtH" /> <input type="button" onclick="javascript:compute();" value="compute"/><br/>
        <span id="resultHolder"/>
    </form>
    </body>
</html>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
View Public Profile Visit tripy's homepage!
 
Old 11-27-2009, 03:28 AM Re: I need a calculator (plug and play) stumped
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, again, Chris beat me to the finish line...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
View Public Profile Visit tripy's homepage!
 
Old 11-27-2009, 03:35 AM Re: I need a calculator (plug and play) stumped
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Ah! but I only did a mph/kph conversion from my script library so it was fairly easy
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 11-27-2009, 03:54 AM Re: I need a calculator (plug and play) stumped
webspace's Avatar
Super Spam Talker

Posts: 933
Name: Buck Roberts
Location: Astoria, Oregon, United States
Trades: 0
Thanks guys. Truely appreciated.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
blog about paintings, drawings and photographs.

Please login or register to view this content. Registration is FREE
Weapons system and aerospace components
webspace is offline
View Public Profile Visit webspace's homepage!
 
Old 12-11-2009, 04:29 PM Re: I need a calculator (plug and play) stumped
Banned

Posts: 1
Name: dgf
Trades: 0
Wonderful! thanks for the info that you guys have been discussing. Awesome!!!!
attrifir is offline
View Public Profile
 
Closed Thread     « Reply to I need a calculator (plug and play) stumped
 

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