Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey all.
Just wondering if someone could tell me what im doing wrong.
New to coding have done a few things like this but it doesn't seem to work :/
Below is the code

What I have tried:

HTML
<!DOCTYPE html>
<html>
	<head>
		<script>	
			var $ = function(id){ //gets information from the text box to rest of script
				return document.getElementById(id);
			} //end of dollar function 
			
			function calculateArea(){ //calculates the area using the users input
				
				var width = document.getElementById("width")".value;
				var length = document.getElementByID("length").value;
				var area = length.value * width.value; //calculation for area
				area = area.toFixed(2); 
				var perimeter = width * 2 + length * 2;
				
				document.getElementById('area').value = area;
				
				document.getElementByID('perimeter').value = perimeter;
			
				
						
			} //end of calculateArea function
			
			function calculatePerimeter (length,width){ //calculates the perimeter using the users inputs
				
				var perimeter = width.value*2 + length.value*2; //calculation for perimeter 
				perimeter = perimeter.toFixed(2);
			
				return perimeter; //outputs the calcultion
			} //end of calculatePerimeter function

						
			function processEntries(){ 
				
				var length = parseFloat($("length").value);
				var width = parseFloat($("width").value);
				
				$("area").value = calculateArea();
				$("perimeter").value = calculatePerimeter();
				alert("test"); 
					
					
			}
			
			} //end of processEnteries
			window.onload = function(){ //waits for the user to click the button then processes
				alert("test1");
				$("calculate").onclick = processEntries; //processes input
				$("length").focus();		//makes it flash waiting for users input			
			
			}// end of button on click command
		
		
		
		</script>	
	</head>
	
	<body>
		<main>	 
			<h1> Area & Perimeter Calculator </h1><br> 
			<label for="intructions">Enter numerical values below and click "Calculate".</label><br>
			<p><label for="length">Length:  </label>
			<input type="text" id="length"><br>
			<label for="width">Width:  </label>
			<input type="text" id="width"><br>
			<label for="area">Area:   </label>
			<input type="text" id="area"><br>
			<label for="perimeter">Perimeter:   </label>
			<input type="text" id="perimeter"><br>
			
			<label> </label> 
			<input type="button" id="calculate" value="Calculate Area and Perimeter">
		
		</br></br></br></br></p></br></br></main>
	</body>
	
</html>
Posted
Updated 5-Sep-16 19:50pm
v3

var area = length.value * width.value;
Just try area = length *width; instead.
 
Share this answer
 
Comments
Member 12721687 6-Sep-16 17:41pm    
Thanks a lot for your help!
There are many errors in your page, here is just a few.
Start by replacing
JavaScript
var width = document.getElementById("width")".value;

with
JavaScript
var width = document.getElementById("width").value;

and remove a } at the end of processEntries().

Your browser have tools to help you debug your page, with FireFox, itis in Tools > Web Developer >
There, you get a Web Console and debugger
 
Share this answer
 
Comments
Member 12721687 6-Sep-16 17:41pm    
Thanks so much!
Patrice T 6-Sep-16 17:48pm    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900