Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Other Help needed, please . javascript math calculation

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-26-2012, 10:31 PM PM User | #1 pixomanic New to the CF scene   Join Date: Feb 2012 Posts: 4 Thanks: 2 Thanked 0 Times in 0 Posts Help needed, please . javascript math calculation Hi im construction engineer and trying to build web app for my use. program to calculate distance and bearing between two points. it is thing i use quite frequently. so i ve done distance bit, but cannot work out bearing part of it. by the way i have program written in basic for casio calculator. so im trying kinda convert it into js and html. Please i need help. would be very thankful. function writeText (form) { var E1=form.inputbox1.value; ----this is where i get coordinates for two var N1=form.inputbox2.value; points var E2=form.inputbox3.value; var N2=form.inputbox4.value; var E; var N; E=(E2-E1)*(E2-E1); N=(N2-N1)*(N2-N1); form.inputbox5.value = Math.sqrt(E+N); ///thats the distance calculation. } var B; if ((N2-N1)<0) { B = Math.atan((E2-E1)/(N2-N1)+180); } else if ((N2-N1)>0) { B = Math.atan((E2-E1)/(N2-N1)); } else if (E>0) { B=90; } else { B=270; return B; } if (form.inputbox6.value<0){ form.inputbox6.value+360=Bearing} }
 02-26-2012, 10:59 PM PM User | #2 devnull69 Senior Coder   Join Date: Dec 2010 Posts: 2,353 Thanks: 11 Thanked 557 Times in 550 Posts You must not change the positions of the two operands of the = assignment operator. Left hand side must be a simple variable name whereas the right hand side can be any expression Code: `Bearing = form.inputbox6.value+360`
 02-27-2012, 12:50 AM PM User | #3 pixomanic New to the CF scene   Join Date: Feb 2012 Posts: 4 Thanks: 2 Thanked 0 Times in 0 Posts hi thanx for ur reply, appreciate that. if u had couple minutes would look thru this for me, i get error, i could do with few tips, to direct me the right way. thats my html
Eastings 1:
Northings 1:

Eastings 2:
Northings 2:

Distance:

Bearing:
and js function writeText (form) { var E1=form.inputbox1.value; var N1=form.inputbox2.value; var E2=form.inputbox3.value; var N2=form.inputbox4.value; var E; var N; E=(E2-E1)*(E2-E1); N=(N2-N1)*(N2-N1); form.inputbox5.value = Math.sqrt(E+N); } var B; if ((N2-N1)<0) { B = Math.atan((E2-E1)/(N2-N1)+180); } else if ((N2-N1)>0) { B = Math.atan((E2-E1)/(N2-N1)); } else if (E>0) { B=90; } else { B=270; } if (form.inputbox6.value<0){ Bearing=form.inputbox6.value+360} } thanx again appreciate u spendin time on it
 02-27-2012, 08:06 AM PM User | #4 devnull69 Senior Coder   Join Date: Dec 2010 Posts: 2,353 Thanks: 11 Thanked 557 Times in 550 Posts Your error might have something to do with your "weird" bracketing. Your function writeText() ends in line 14, the rest is outside of the function in the global scope and will be executed BEFORE the function. All the variables local to the function (like E1, N1, E2, N2, E and N) will not be available there. I see no place where you actually call the function. The } curly bracket in the end doesn't have a matching opening { curly bracket. Btw, please use the [ code ] and [ /code ] (without spaces) to post code here. You can easily achieve that by clicking on the # octathorpe symbol (not the #i symbol) above the text box.
 Users who have thanked devnull69 for this post: pixomanic (02-28-2012)
 02-28-2012, 01:03 AM PM User | #5 pixomanic New to the CF scene   Join Date: Feb 2012 Posts: 4 Thanks: 2 Thanked 0 Times in 0 Posts Thanx thanx again, after ur fair comment about my 'weird' syntax i decided to go back to the book, anyway i managed to get it working but it returns in radians, cant get conversion formula to work /radians*(180/PI) / Code: ```
Eastings 1:
Northings 1:

Eastings 2:
Northings 2:

Distance:

Bearing:
```
 02-28-2012, 08:42 AM PM User | #6 devnull69 Senior Coder   Join Date: Dec 2010 Posts: 2,353 Thanks: 11 Thanked 557 Times in 550 Posts This is because PI is not defined. Use Math.PI instead Code: `A=B*(180/Math.PI)`
 Users who have thanked devnull69 for this post: pixomanic (02-28-2012)
 02-28-2012, 10:58 PM PM User | #7 pixomanic New to the CF scene   Join Date: Feb 2012 Posts: 4 Thanks: 2 Thanked 0 Times in 0 Posts Thanx Thank you very much for all ur help, excellent stuff. much appreciated. Andy

 Bookmarks

 Tags bearing, distance, javascript, math

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 06:05 AM.