Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
New Javascripter - problems with functions
Old 03-05-2008, 11:39 PM New Javascripter - problems with functions
Novice Talker

Posts: 5
Name: Sean
Trades: 0
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">&nbsp;</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
sean2me is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-06-2008, 12:27 AM Re: New Javascripter - problems with functions
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Use FireFox for debugging JavaScript code because the Error Consol on FF is the best to use as it will give you line numbers and hilite offending errors in the source code.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to New Javascripter - problems with functions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18873 seconds with 12 queries