I am trying to learn Javascript on my own, its proving sneaky and difficult! When I run the code pasted below, I get errors such as "object expected". I don't know what that means, or how to fix it. It seems my variables are all good, it then seems my problem is the return function.
I am trying to return a value to the azimuth and distance input boxes (is that possible?)
Also, I am noticing different types of javascript, one being a standard type, the other being DOM (have I got that right). I was wondering if I am mixing types without knowing, and maybe creating incompatible coding?
I am also curious about how to calculate. For instance I understand Math.sqrt() is a squareroot function, however my browser states that Math is undefined?? If anyone can help set me straight on this, it would be most appreciated! I must be close, I just need someone to push me over!!
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="javascript">
function DELTA(north1,north2,east1,east2)
{
var north1=Number(north1)
var north2=Number(north2)
var east1=Number(east1)
var east2=Number(east2)
dN=north2-north1
dE=east2-east1
alert(dN + " "+ dE)
}
function AZIMUTH_CALC(north1,north2,east1,east2)
{
var north1=Number(north1);
var north2=Number(north2);
var east1=Number(east1);
var east2=Number(east2);
var AZ=(east2-east1)/(north2-north1)
alert(AZ)
return(AZ)
}
</script>
<script type="javascript">
function DISTANCE_CALC(north1,north2,east1,east2)
{
var north1=Number(north1)
var north2=Number(north2)
var east1=Number(east1)
var east2=Number(east2)
var DIST=Math.sqrt(((east2-east1)^2)+((north2-north1)^2));
alert(DIST);
return(DIST);
}
</script>
<script type="javascript">
function inverse1()
{
north1=document.FORM_1.north1.value;
north2=document.FORM_1.north2.value;
east1=document.FORM_1.east1.value;
east2=document.FORM_1.east2.value;
alert("Azimuth = " + AZIMUTH_CALC(north1,north2,east1,east2) + " Distance = " + DISTANCE_CALC(north1,north2,east1,east2))
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>COORDINATE INVERSE</title>
</head>
<body>
<form method="post" name="FORM_1" target="_self" id="FORM_1">
<table width="200" border="0" summary="Calculate simple inverse between two points.">
<caption align="top">
Coordinate Entry
</caption>
<tr>
<th scope="col"> </th>
<th scope="col"> Point # 1 </th>
<th scope="col">Point # 2 </th>
</tr>
<tr>
<th scope="row"><div align="right">Northing</div></th>
<td><input type="text" name="north1" value="750000" tabindex="1"></td>
<th scope="col"><input type="text" name="north2" value="700000" tabindex="3"></th>
</tr>
<tr>
<th scope="row"><div align="right">Easting</div></th>
<td><input type="text" name="east1" value="550000" tabindex="2"></td>
<th scope="col"><input type="text" name="east2" value="500000" tabindex="4"></th>
</tr>
</table>
<p>
<input name="button" type="button" tabindex="5" value="CALC" onClick="inverse1(north1,north2,east1,east2)">
</p>
<p>
<label for="textfield">Azimuth: </label>
<input type="text" name="AZIMUTH_CALC" id="AZIMUTH_CALC" value="AZ" tabindex="6" border="0">
<label for="label">Distance: </label>
<input type="text" name="DISTANCE_CALC" id="DISTANCE_CALC" value="DIST" tabindex="7" border="0">
</p>
</form>
</body>
</html>
Last edited by chrishirst; 03-06-2008 at 06:00 AM..
Reason: Didn't include my updated code
|