home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Java Script Help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1961
Discussions: 200,936, Posts: 2,379,224, Members: 246,301
Old April 19th, 2009, 08:00 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Apr 2009
Posts: 4
Java Script Help

I need help with my script. I am trying to figure out the lowest maximum heart rate and highest maximum heart rate for exercise. New to javascript any help would be greatly appreciated.

here's what i have so far

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>HeartRate</title>
<script>
var age
max = function maxHeartRate(age)
{
(220-age);
}
</script>
</head>
<body>
<form>
<p>Age<input type="text" id="year" name="Year"></p>
<input type="button" value="Age Input" name="Age">
<onclick = maxHeartRate(age)>
</form>
<script>
var lowestTarget= max*.5
var maxTarget = max*.85
document.write("<p>" + "Max heart rate is " + max + "</p>");
document.write("<p>" + "Maximun Target rate is " + maxTarget + "</p>");
document.write("<p>" + "Lowest max rate is " + lowestTarget + "</p>");
</script>
</body>
</html>
machackr is offline   Reply With Quote
Old April 21st, 2009, 12:30 AM     #2 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,083
Send a message via AIM to sr71000
JavaScript Tutorial

I don't want to be discouraging but there are a few errors here. Have you done much html? Have you done any other javascript? Check out the tutorial above and go through that first. Once you make it through that tutorial this should be much easier. I started responding below so you can see some of the stuff that's wrong. I didn't finish though because I found a few more errors and your problems are more just with fundamental understanding than with syntax.

the way you create your function is a little off. maybe javascript is different, as i'm not too familiar with it, but in the languages I use, you can't create a function like that and assign it to a variable. you need to create a function by just getting rid of the "max =" part.

The purpose of a function is to make a block of code that you can call, passing a few arguments with it (in this case, age). Then that function will run and return it's output.
This may not be perfect but it should be closer. Again as I said I don't really know javascript, but i do a lot of programming.
Code:
function maxHeartRate(age)
{
    return (220-age);
}
Then you make a call to that function below it like this

Code:
max = maxHearRate(21);
your html form is a little off. In particular the onclick belongs as an attribute of your submit button, not it's own html tag.

The last big error, which is like I said more theoretical is the second script. that script wont' run every time the button is clicked. That run's once when the page is loaded. The text won't automatically change whenever max changes. In other words the script won't sit there and wait for it's variables to change and then change the html. Hope that makes sense.
sr71000 is offline   Reply With Quote
Old April 21st, 2009, 11:10 AM     #3 (permalink)
Junior Member
 
Join Date: Apr 2009
Posts: 4
Thanks for explaining this sr71000 this is my first time using javascript. I finnaly dulled it down to the simplest possble way i knew how by using a user prompt to get the age and then used statments rather than a function to calculate everything.

here's what i have now

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<script type="text/javascript">
var age = prompt("What is your age?", "Type your age here");
var max;
var maxTarget;
var lowestTarget;
max=(220-age);
maxTarget=(max*.85);
lowestTarget=(max*.5);
document.write("<p>" + "Max heart rate is " + max + "</p>");
document.write("<p>" + "Max target rate is " + maxTarget + "</p>");
document.write("<p>" + "Lowest target rate is " + lowestTarget + "</p>");
</script>
</body>
</html>
machackr is offline   Reply With Quote
Old April 21st, 2009, 12:29 PM     #4 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,083
Send a message via AIM to sr71000
Hey. Did that work for you? I'm not familiar enough with javascript to be able to look at it and just say for sure that it looks like it should work. I don't see why it wouldn't, but just wondering.

-Kevin
sr71000 is offline   Reply With Quote
Old April 21st, 2009, 04:13 PM     #5 (permalink)
Junior Member
 
Join Date: Apr 2009
Posts: 4
Yes it worked
machackr is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java script help Network67 Applications and Operating Systems 0 March 25th, 2005 04:48 AM
Java Script - Help! rcwabbits Webmastering and Programming 0 April 24th, 2003 11:44 PM
Java script and IE Bill in SD, CA Applications and Operating Systems 2 April 10th, 2003 03:39 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
windows 7 problem (5)
Is It Just Me? (2895)
Wireless Televisions. (8)
California Passes Anti-Flat-HDTV Le.. (39)
Obama the Muslim (14)
Is the PSU I received dead? (10)
windows vista security holes (9)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
EVGA 9800 gtx help with finding a g.. (8)
Recent Discussions
windows 7 problem (5)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
Wireless Televisions. (8)
CPU fan stops spinning randomly (3)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Partition Magic caused HDD problem (2)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Regular Build (3)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Have you switched yet? (84)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)
Wireless speakers for PC? (11)


All times are GMT -4. The time now is 11:15 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28