User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,767 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3078 | Replies: 2
Reply
Join Date: Sep 2007
Posts: 2
Reputation: amol0010 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
amol0010 amol0010 is offline Offline
Newbie Poster

Javascript Function return value into PHP or not ?? Please help !!

  #1  
Sep 3rd, 2007
I have asked this question earlier, but could not get a reply that
worked :-(


I have a single login_success.php file where I have written a function


IsWithinFixedGeofence(point)


{......


....


...
if ( distance <= MINIMUMDISTANCE )
{
return PointsOfInterest[i];


}



I want to be able to store the following three properties of
PointsOfInterest. I am not sure if I need the command "return" as
well. All I want to do is store:

1) index i
2) .lat
3) .lng


into 3 PHP variables.


something like -




IsWithinFixedGeofence(point)


{......


....


...
if ( distance <= MINIMUMDISTANCE )
{
<? $lat ?> = PointsOfInterest[i].lat;


<? $lng ?> = PointsOfInterest[i].lng;


<? $index ?> = i;


}



and then be able to use $lat, $lng to center the map to that point.

[inlinecode]
// Display the map, with some controls and set the initial location
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng( <? $lat ?>, <? $lng ?>),15);


and use the index in a dynamic SQL query like this -


$result = mysql_query("SELECT cities.cityname, cities.citybuslink,
markers.information, markers.name, markers.address , markers.picture
FROM cities, markers where markerid = <? $index ?> AND markers.cityid =
cities.cityid ");


Do I really need to store the JS function return value into PHP variables or can I use the function IsWithinFixedGeofence()'s return value as a source everywhere else too ?

Something like

IsWithinFixedGeofence().lat

IswithinFixedGeofence().lng

and

IsWithinFixedGeofence().index



I heard AJAX would also work with something like this, but I am not
sure how to use it in this context..


I would be extremely grateful if you could help me with this
problem.


Best regards,
Amol
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Rep Power: 5
Solved Threads: 34
Moderator
Staff Writer
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: Javascript Function return value into PHP or not ?? Please help !!

  #2  
Sep 4th, 2007
Since JavaScript runs in the browser after PHP os processed on the server the only way to get this information to the server is to submit the data as either POST or GET data or use Ajax. But you can't affect the PHP used to render the page as it is long done processing the page by the time the JavaScript comes into play.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote  
Join Date: Sep 2007
Posts: 2
Reputation: amol0010 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
amol0010 amol0010 is offline Offline
Newbie Poster

Re: Javascript Function return value into PHP or not ?? Please help !!

  #3  
Sep 4th, 2007
Hi there,

Thanks very much for the reply.

I just figured out that instead of passing the javascript variables into PHP, I should store these into JS variables only.


if I use this code


IsWithinGeofence(point)
{
....
...

if(distance <= minimiumdistance)

{
document.write(PointsOfInterest[i].lat);
}

}



It displays the correct value of lat from the database. in case here 56.4856.


I declared 3 global variables on the top of the document in order to assign them the values of latitude, longitude and index of the PointsOfInterest[i]


i.e.

var latitude =12 ; //12 is assigned just to test if this variable is being correctly assigned or not

var longitude;

var index ;




IsWithinGeofence(point)
{
....
...

if(distance <= minimiumdistance)

{
latitude = PointsOfInterest[i].lat;
longitude = PointsOfInterest[i].lng;
index = i;


}

}



document.write(latitude);

The above command is displaying the value 12 instead of getting the value 56.4856 from PointsOfInterest[i].lat

Why is this so ??

Best regards
Last edited by amol0010 : Sep 4th, 2007 at 7:36 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:53 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC