...

View Full Version : pass var to another page



helenp
11-24-2011, 01:19 PM
Hi,
dont get it, thought was easy but cant make it work.

I have a calculator script which at this moment calculate on the same page using php and # (the page refreshes and jumps to a point in the page.
On every page a var is declared manually like this:
$propiedad="name_of_property";

I am trying to add hijax to the calculator, so I need to point the form thats included in the page to another page, or point to another page in the javascriptfile if I do it another way (prefered as the non ajax version would be displayed on same page also), the problem none of the ways work as I dont have the property var passed to the result page, I been trying everything but I just cant find out how to pass the var. And the value of the var cant be defined as it is diferent on each page, I need to pass the var $propiedad with the value thats on each page using the form, the javascript file and as a last option sessions as I dont like them.
Any help would be appreciated.
I have researched and tried but cant manage.
Thanks

tangoforce
11-24-2011, 01:51 PM
You can either pass it in the url - www.yoursite.com/index.php?propid=<value> or you can put it in a form and post it.

Then you need to get it from either the $_GET (url) or $_POST (form) arrays.

IF you need that same value to be available on multiple pages then store it in the $_SESSION array instead. Be sure to use session_start() at the top of each script that uses the $_SESSION array.

helenp
11-24-2011, 02:35 PM
You can either pass it in the url - www.yoursite.com/index.php?propid=<value> or you can put it in a form and post it.

Then you need to get it from either the $_GET (url) or $_POST (form) arrays.

IF you need that same value to be available on multiple pages then store it in the $_SESSION array instead. Be sure to use session_start() at the top of each script that uses the $_SESSION array.

Thanks, will try the url one, but not sure that is good, how do I do in the form as I dont have the value? sorry but been trying for hours and nothing.
Session I think unnesesarry as the same form are included on all pages.
Thanks in advance if you can give an example, please.

tangoforce
11-24-2011, 03:45 PM
Unless you have code to show us so that we can see what you're trying to acheive, its difficult to know what sort of example to provide really.

What code do you have so far?

helenp
11-24-2011, 05:32 PM
Unless you have code to show us so that we can see what you're trying to acheive, its difficult to know what sort of example to provide really.

What code do you have so far?
The php script is a very long script with many ifs and else so I want past that.
On the property pages I have the var $propiedaded written manually
like this $propiedad="name_of_property"; this var changes on all pages.
This I have in pages where the form is:
<div id="output">
<div id="output2">
<div class="calculator">
<script src="ao.js" type="text/javascript"></script>
<script src="hijax2.js" type="text/javascript"></script>
<?php
include("calculateformnew2.php");
?>

</div></div></div>
Also normally I have the phpquery and result included, however the ajaxscript is diferent.
The form (in the includes there is a dropdown where you can choose year-month and another for the day, one for arrival and one for departure:


<form method="post" action="calculator4.php">
<p class="calculatortext">Arrival: <?php include("includes/day.php"); ?><?php include("includes/month.php"); ?>
Departure: <?php include("includes/day2.php"); ?><?php include("includes/month2.php"); ?> </p>
<p>
<input class="boton" size="10" type="submit" name="enviar" value="Calculate/Check">
</p>
</form>

The ajaxfile hijax.js:


var getQuery = function(){
var dayllegada = document.getElementById("day").value;
var daysalida = document.getElementById("day2").value;
var monthllegada = document.getElementById("month").value;
var monthsalida = document.getElementById("month2").value;
return "ajax=true&day=" + encodeURI(dayllegada) + "&day2=" + encodeURI(daysalida)
"&month=" + encodeURI(monthllegada) "&month2=" + encodeURI(monthsalida);
}
var setQuery = function()
{
var frm = document.getElementsByTagName("form")[0];
frm.onsubmit = function(){
var query = getQuery();
myHijax(query);
return false;
}
}

var myHijax = function(qs)
{
var x = new AO("calculator4.php",qs);
x.onload = function()
{
if (x.init && x.status == "200")
x.putHere("output");
}
x.post();
return false;
}

window.onload = function(){
var bSupport = new AO();
if (bSupport.init) { // test for support of Ajax
setQuery();
bSupport = null;
}
else return false;
}

As you can see the script is in calculator4.php so I need to pass the var there.
Thanks in advance

tangoforce
11-24-2011, 05:54 PM
So you could do this then?
new AO("calculator4.php?param=value",qs);

Then in calculator4:
$Param = $_GET['param'];

helenp
11-24-2011, 09:21 PM
So you could do this then?
new AO("calculator4.php?param=value",qs);

Then in calculator4:
$Param = $_GET['param'];

I did not get it to work, suppose I do it not correctly,
anyway I managed to pass with the form in a hidden field :)

However cant get the ajax to work, suppose as the query is very complicated with several if and else :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum