3 Replies - 2139 Views - Last Post: 04 January 2013 - 10:00 AM

#1 sarahi24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-May 12

Problem with coding an html project using a calc function

Posted 16 May 2012 - 10:40 PM

Hi everyone, i have been stuck on this problem for a while.
My assignment ask to create a web page that will calculate the BMI of a person by using the formula weight*703/(height*height).

I created my code but I am so confused about how to place the formula, and what values to use for the text boxes.
should i use the same function twice, where does the height part belong in?
this is what it asks.

create a script with a function named calcBMI(): I did
it performs the calculation using the values in the weight: i get that

Reference the text boxes from within the function by using the document object, form name, and name and value attributes of the text boxes(do not use function arguments)- this part has me lost. help please!
here's my code;
<!DOCTYPE HTML>
<html>
<head>
    <title>Don's Weddings Guestbook</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link href="style.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
	function calcBMI(){
		calculation -= yourweight;
		yourweight = document.discription.weight.value *703;
		calculation += yourweight;
		document.calculation.BMI.value = ""
	}
	
	/* <![CDATA[ */
	/* ]]> */
	</script>
</head>
<body>
<form action="" name="discription">
		<P>Weight
		   <input type="text" name="weight" style="width: 180px" onchange="calcBMI()"/></p>
		<p>Height
		   <input type="text" name="height" style="width: 152px" onchange="calcBMI()"/></p>
</form>
<form action="" name="calculation">
		<p>BMI
		   <input type="text" name="BMI" style="width: 152px" onchange="calcBMI()"/></p>
										
		<p><input type="button" value="calculate" onclick="addGuest()"/></p>
		</form>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with coding an html project using a calc function

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: Problem with coding an html project using a calc function

Posted 16 May 2012 - 10:51 PM

For god's sake people, Javascript and Java are not the same thing! Moved to the Javascript forum.

:)
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: Problem with coding an html project using a calc function

Posted 16 May 2012 - 10:57 PM

So you are on the right track. You are referencing the boxes correctly, you just need to use them all...

function calcBMI(){
    var yourweight = document.discription.weight.value;
    var yourheight = document.discription.height.value;

    document.discription.BMI.value = yourweight * 703/(yourheight * yourheight);
}



Make sure you put your BMI field into the discription form. No need to make it a separate form here. Then call calcBMI() from your button click event.

Note: Make sure that you enter only numbers. Otherwise you will get an error.
Was This Post Helpful? 0
  • +
  • -

#4 SpAm101  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 54
  • Joined: 28-November 12

Re: Problem with coding an html project using a calc function

Posted 04 January 2013 - 10:00 AM

Got to be the longest SPAM post I've ever seen :lol:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1