PDA

View Full Version : Pass Variables



bharathbs
08-12-2008, 06:30 AM
<a href="#" onclick="openmypage(); return false">data from the file.</a>
when i click on the link i need to carry two variables from the file which is in an array to a DHTML page which i have defined in the openmypage() function. can anyone please tell my how i can carry the 2 variable from the record which is in a file.

jscheuer1
08-12-2008, 03:46 PM
We need more information. What variables are you trying to pass? Where are you trying to pass them? Why do you need to - what will it help?

Also:

Please post a link to the page on your site that contains the problematic code so we can check it out.

bharathbs
08-14-2008, 05:08 AM
<script type="text/javascript">

function openmypage(){

ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php", "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")

ajaxwin.onclose=function(){return window}

}

</script>
<td><?php printf("%03d.",$number++); ?> </td>
<?php /* Print S.Number */ ?>
<td><?php printf("%s%s-%s%s-%s%s",$DataArray[1][0],$DataArray[1][1],$DataArray[1][2],$DataArray[1][3],$DataArray[1][4],$DataArray[1][5]); ?></td>
<?php /*Print Date */ ?>
<td><?php printf("%s%s:%s%s:%s%s",$DataArray[0][0],$DataArray[0][1],$DataArray[0][2],$DataArray[0][3],$DataArray[0][4],$DataArray[0][5]); ?></td>
<?php /*Print Time */ ?>

<td><?php printf("%s",$DataArray[4]); ?></td>
<?php /*Print Speed */ ?>
<td><?php printf("%3.1f",$DataArray[5]); ?></td>
<?php /*Print Distance */ ?>

<?php session_start();
$_SESSION["lat"] = $DataArray[2];
$_SESSION["long"] = $DataArray[3];
?>
<td><b><a href="#" onClick="openmypage(); return false"><?php printf("%s",$DataArray[6]); ?></a></b></td>
<?php /*Print Location */ ?>
</tr>

the $DataArray[2] and $DataArray[3] contains the latitude and longitude which i am taking from a file(which has many records), so my problem is i need to take these two variables to a DHTML page and plot it on the map. If you can help me carry the two variables to this page plotting will be simple. Please help me out as i am stuck with this from a week. I am continuing a work done by someone else.
to be more clear the web site is www.versabyte.org, login using guest as username and password. click on veh3 button and movement report, by choosing the start and end date.
waiting for reply .
thanking you in advance.

jscheuer1
08-14-2008, 06:30 AM
It's still really not all that clear to me what you are after. However, once you set:


<?php session_start();
$_SESSION["lat"] = $DataArray[2];
$_SESSION["long"] = $DataArray[3];
?>

Those values (unless they are changed) should be available on any page with the .php extension (like your result.php page) as:

$_SESSION["lat"]

and:

$_SESSION["long"]

respectively. This would make passing them via javascript redundant, and therefore unnecessary. You could pick them up in a script on such a page like so:


<script type="text/javascript">
var jlat = <?php echo $_SESSION["lat"]; ?>;
var jlong = <?php echo $_SESSION["long"]; ?>;
</script>

Once that is done, any other javascript on the page after that would have those values available to it as:

jlat

and:

jlong

respectively.

bharathbs
08-14-2008, 11:10 AM
there is a csv file which contains the date,time,speed,distance,location. i tabulate this on a webpage using php and html. There are some "n" no. of records in the csv file.
my problem is..
when i click on the "location" (which is a hyperlink), i need to take the latitude and longitude from the csv file (as i told you earlier $DataArray[2] and $DataArray[3] contains the lat and long respectively) to the DHTML page.
The code which i posted carries the last record(lat,long) in the file in the session variables whenever i click on any of the links(location is the hyperlink) in the table(which contains date,time,speed,distance,location).

What i need is...

Whenever i click on a location(link) i need its respective latitude and longitude value($DataArray[2] and $DataArray[3] ) carried to the DHTML page.

Please Help..
thanking you..

jscheuer1
08-14-2008, 01:40 PM
As arrays or as single numeric or string values? Do the session variables contain arrays or single numeric or string values?

If the data is there as a PHP array, you would have to iterate it on the target page into a javascript array, if it is just a single string or numeric value, it can be grabbed just as I already mentioned. If the session variable no longer necessarily contains the desired value or array by the time the target page is loaded, it would probably be best to also set a session variable that would, so that it can be grabbed on the target page.

Otherwise you would need to get or post it to the target page anyway, which might interfere with other get or post data or cause some other issue. If using a get, it could be grabbed from the URL via javascript or a combination of javascript and PHP. If post, PHP would be needed. The only way you could pass it directly to the new page is if you were writing the new page entirely from scratch using javascript on the originating page. I haven't seen enough of the code to tell how you are doing that, but got the impression that the target page is an actual page, in which case you cannot write to it directly from the originating page via javascript without overwriting it. In any case changes made to it like that would be extremely temporary.

bharathbs
08-16-2008, 08:59 AM
As arrays the lat long are stored which is in a file. Session variables contain arrays($DataArray[2] and $DataArray[3]). when i create a <href> to the location column, the DHTML page opens up. ive used the session variables to carry the lat long, but whenever i click on any location link, it carries the last value in the table but not the one which im clicking on.
thanking you..

jscheuer1
08-16-2008, 09:27 AM
Then you could do something like so:


<script type="text/javascript">

function openmypage(lat, longi){
if(lat && longi)
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php?plat=" + lat + "&plong=" + longi, "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
else
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php", "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
ajaxwin.onclose=function(){return window}

}

</script>
<td><?php printf("%03d.",$number++); ?> </td>
<?php /* Print S.Number */ ?>
<td><?php printf("%s%s-%s%s-%s%s",$DataArray[1][0],$DataArray[1][1],$DataArray[1][2],$DataArray[1][3],$DataArray[1][4],$DataArray[1][5]); ?></td>
<?php /*Print Date */ ?>
<td><?php printf("%s%s:%s%s:%s%s",$DataArray[0][0],$DataArray[0][1],$DataArray[0][2],$DataArray[0][3],$DataArray[0][4],$DataArray[0][5]); ?></td>
<?php /*Print Time */ ?>

<td><?php printf("%s",$DataArray[4]); ?></td>
<?php /*Print Speed */ ?>
<td><?php printf("%3.1f",$DataArray[5]); ?></td>
<?php /*Print Distance */ ?>

<?php session_start();
$_SESSION["lat"] = $DataArray[2];
$_SESSION["long"] = $DataArray[3];
?>
<td><b><a href="#" onClick="openmypage('<?php echo $_SESSION["lat"]; ?>', '<?php echo $_SESSION["long"]; ?>'); return false"><?php printf("%s",$DataArray[6]); ?></a></b></td>
<?php /*Print Location */ ?>
</tr>

If the method for opening (request.open()) is GET in the main AJAX routine, and perhaps even if it is POST, the queries should then be available on the result.php page as:


$_Get["plat"]

and:


$_Get["plong"]

respectively.

bharathbs
08-16-2008, 10:52 AM
Im trying to use this code which u sent me but when i clicked on the created link (location) im directed to the top of the page.
i.e when i scroll down and click on the link I'm directed to the top of the page(scrolled up) with a "#" added to the URL.. The DHTML page does not open up at all... I'm totally stuck.. and i'm not able to figure out the problem...

i did not get you.. "opening (request.open())"... what is request.open()

please advice..
thanking you..

jscheuer1
08-16-2008, 11:37 AM
There is a javascript error. The onclick event is not firing and the href of # is. We would need to find the error and go from there. If you know nothing about how AJAX works, don't worry about the request.open() method yet. It should have nothing to do with the current problem, but may be important later.

It appears long is reserved, use this version of the function (I'll fix it in the original post):


function openmypage(lat, longi){
if(lat && longi)
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php?plat=" + lat + "&plong=" + longi, "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
else
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php", "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
ajaxwin.onclose=function(){return window}

}

The links on report.php at least look like they are writing out correctly with the lat and long coords. There could be other problems. Let's take care of the one we know about first (replace the function).

One other thing I noticed though was that the page appears to be writing out the function for each record. The function only needs to appear on the page once. It shouldn't hurt anything it getting written so many times, but it is a waste of effort.

bharathbs
08-18-2008, 04:18 AM
hi Mr. John,
I did replace the function but its the same problem. I am totally confused..
please help..
thanking you..

jscheuer1
08-18-2008, 05:20 AM
I must have made a typo, because I see now that there are two missing quote marks, use this version:


function openmypage(lat, longi){
if(lat && longi)
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php?plat=" + lat + "&plong=" + longi, "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
else
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/result.php", "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
ajaxwin.onclose=function(){return window}

}

But you must have changed something else because now we no longer have clickable links or the latitude and longitude in the generated source code.

Go back to what I had in post #8:

http://www.dynamicdrive.com/forums/showpost.php?p=157393&postcount=8

I've fixed the typos and other problems in it, and at least that was generating the proper links with the latitude and longitude.

bharathbs
08-18-2008, 06:40 AM
hi,
the dhtml page is opening now, the problem was i had to terminate the code in the script.
the session variables are being passed in the result.php now thanks a lot for that.
But in this result.php im trying to open the google map with the google map api. It is not responding can you help me on that.

thanking you,

jscheuer1
08-18-2008, 01:12 PM
Now, you are pretty much just having a problem with AJAX and javascript. The easiest solution would probably be to use the iframe method of DHTML window:


function openmypage(lat, longi){
if(lat && longi)
ajaxwin=dhtmlwindow.open("ajaxbox", "iframe", "windowfiles/result.php?plat=" + lat + "&plong=" + longi, "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
else
ajaxwin=dhtmlwindow.open("ajaxbox", "iframe", "windowfiles/result.php", "Location", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
ajaxwin.onclose=function(){return window}

}

bharathbs
08-19-2008, 07:54 AM
hi Mr.John,
Thank you for giving me your time and helping, its working fine..
regards,
bharath.