oldskool
Oldie but a goodie
- Messages
- 1,760
- Location
- Maine, USA
*Disclaimer: This is a homework problem, BUT all I need is one little nudge. I can't seem to find the answer to my problem anywhere...
I am writing a simple code for entering your age, and after clicking the button I get the target heart range zone. I know what the problem is, but not how to fix it. I have highlighted the part where I am stuck. Here's the code:
To make sense of it, I will tell you what is supposed to happen. You enter your age, it gets subracted from 220. The answer gets multiplied by .5 and .85, thus yielding a minimum and maximum heart rate in b.p.m. for any given age. What I am having the problem with is I can't seem to find is the syntax for text entered into the text box to be converted to a variable.
Like for example, I am attempting to have the parseInt function pass the string argument entered in the text box, which is that person's age, and send it to the yourAge variable. All the rest of the program works fine. Any help would be greatly appreciated.
I am writing a simple code for entering your age, and after clicking the button I get the target heart range zone. I know what the problem is, but not how to fix it. I have highlighted the part where I am stuck. Here's the code:
To make sense of it, I will tell you what is supposed to happen. You enter your age, it gets subracted from 220. The answer gets multiplied by .5 and .85, thus yielding a minimum and maximum heart rate in b.p.m. for any given age. What I am having the problem with is I can't seem to find is the syntax for text entered into the text box to be converted to a variable.
Like for example, I am attempting to have the parseInt function pass the string argument entered in the text box, which is that person's age, and send it to the yourAge variable. All the rest of the program works fine. Any help would be greatly appreciated.
Code:
<html>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Target Heart Rate Page - Case Project 3-2 by Eric Maddan</title>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
<head>
<p><form name="heartRate"><b>Enter your age</b><br><br>
<script type="text/javascript">
/* <![CDATA[ */
//code written by Eric Maddan
[I][B]var yourAge=parseInt( );[/B][/I]
// ^ ^ I know this is wrong, but can't find the syntax to convert user's input from text box to variable.
var strtNumber=220;
var formulaNumber=parseInt(strtNumber - yourAge);
var trgtStatement;
var minTargetrate=parseInt(formulaNumber * .5);
var maxTargetrate=parseInt(formulaNumber * .85);
var outBoxtext = (minTargetrate + " to " + maxTargetrate) ;
</script>
<input type="text" name="inputText" size="20"><br><p>
<input name="trgtStatement" size="50"><br /><p>
<input type="button" value="Target Heart Rate"
OnClick="trgtStatement.value=outBoxtext + ' beats per minute ' ;"><p>
</form>
</script>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>
</body>
</html>