/    Sign up×
Community /Pin to ProfileBookmark

Javascipt Weight Calculation Help.

I am trying to get create a page that works like the following. [URL=http://www.thesingers.info/content/students/classes/cis2033online/Xtras/lab03/]Click here to view the page.[/URL] This page uses PHP, I need to create it in Javascript. I have attached a txt file that can be changed to a html file.

If any one can help me get it working that would be great. Keep in mind that the image folder I amusing will be called planetImages, and also keep in mind that I have some of the file coded, the main thing that needs to be fixed is the two main function in the header.

Thanks

[upl-file uuid=4476923f-ffc2-4ff8-9ac3-ddab00585bd5 size=3kB]calculations.txt[/upl-file]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonFeb 19.2005 — Here ya go:
[code=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>Lab03</title>
<script>
function calc()
{
if (document.form.select.value==8) {
document.form.text.value = "There is not enough known about Pluto to calculate its gravity and your weight there."
document.pic.src = Image[document.form.select.value]
}
else {
var planet=new Array();
planet[0]="Mercury"
planet[1]="Venus"
planet[2]="Earth"
planet[3]="Mars"
planet[4]="Jupiter"
planet[5]="Saturn"
planet[6]="Uranus"
planet[7]="Neptune"
planet[8]="Pluto"

var percent=new Array();
percent[0]=".38"
percent[1]=".91"
percent[2]="1"
percent[3]=".38"
percent[4]="2.54"
percent[5]=".93"
percent[6]=".8"
percent[7]="1.2"
percent[8]="unknown"

var Image = new Array(9);
Image[0] = "planetImages/Planet1.jpg";
Image[1] = "planetImages/Planet2.jpg";
Image[2] = "planetImages/Planet3.jpg";
Image[3] = "planetImages/Planet4.jpg";
Image[4] = "planetImages/Planet5.jpg";
Image[5] = "planetImages/Planet6.jpg";
Image[6] = "planetImages/Planet7.jpg";
Image[7] = "planetImages/Planet8.jpg";
Image[8] = "planetImages/Planet9.jpg";


document.form.text.value = "Your weight would be " +(document.form.input.value)*percent[document.form.select.value]+" on "+planet[document.form.select.value]+"."

document.pic.src = Image[document.form.select.value]
}
}
</script>

</head>

<body bgcolor="#000000" text="#FFFFFF">
<div align="center">
<h1>Lab03 - Weight Calculator</h1>
<h2>Use the form below to find your weight on any of the planets in our Solar System</h2>
<table>
<tr>
<td>
<img name="pic" src="planetImages/Planet3.jpg" alt="Planet Image"/>
</td>
<td>
<form name="form">
<table>
<tr>
<td>Your Weight on Earth:</td>
</tr>
<tr>
<td><input type="text" name="input"/></td>
</tr>
<tr><td></td></tr>
<tr>
<td>Select a Planet:</td>
</tr>
<tr>
<td>
<select name="select" onchange="calc();">
<option value="0">Mercury</option>
<option value="1">Venus</option>
<option value="2" selected>Earth</option>
<option value="3">Mars</option>
<option value="4">Jupiter</option>
<option value="5">Saturn</option>
<option value="6">Uranus</option>
<option value="7">Neptune</option>
<option value="8">Pluto</option>
</select>
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>Your weight on the selected planet:</td>
</tr>
<tr>
<td>
<textarea name="text" rows="10">Type your weight into the field above and select a planet to see your weight on other worlds.</textarea>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</body>
</html>

[/code]


-Steve
Copy linkTweet thisAlerts:
@balloonbuffoonFeb 19.2005 — Oops! Change

[code=php]document.pic.src = Image[document.form.select.value][/code]
to
[code=php]document.pic.src = "planetImages/Planet9.jpg"[/code]
in the calc() 'if' command.

-Steve
Copy linkTweet thisAlerts:
@critchey1authorFeb 20.2005 — Thank you so much. You have no idea how much this saved my butt.....
×

Success!

Help @critchey1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...