Click to See Complete Forum and Search --> : pass vaiable to script, using pop-up window


Doug Calli
08-07-2003, 12:53 PM
I need to pass a vaiable from one script to another, ideally
through a pop-up window, as I am trying (unsuccesfully) to do here.

2 Q's:
Is this possible using a java pop-up window?
If so, how do I retrieve the variable in script2? Do I query for the results?

What I'm trying now,.....
<?php

$footer ="
<a href=\"javascript:void(0)\"
onclick=\"window.open('../../SomePathTo/script2.php?VariableName=+$variable+,
'WinName','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,c opyhistory=no,width=350,height=400')\">
<font size='-1' face='Arial,Helvetica,Univers,Zurich BT,sans-serif'>Readable Link Text</font></a>
";

echo "$footer";
?>

Thanks, DC

Edit:
how do I retrieve the variable in script2

Since we didn't address this and others may want to know!;)
The form action was set to - action=""
This causes the form to post to the current window/script, so the variables are available to that script.

At least that's my understanding, someone else may have a better explanation of what is going on.

DaiWelsh
08-08-2003, 10:30 AM
Not sure why you are doing it by echoing a variable, but anyway your output javascript syntax will be a little off, perhaps

<?php
$footer ="<a href=\"javascript:void(0)\"
onclick=\"window.open('../../SomePathTo/script2.php?VariableName=$variable',
'WinName','toolbar=no,location=no,directories=no,s
tatus=no,menubar=no,scrollbars=yes,resizable=yes,c
opyhistory=no,width=350,height=400')\">
<font size='-1' face='Arial,Helvetica,Univers,Zurich BT,sans-serif'>Readable Link Text</font></a>
";

echo "$footer";
?>

is what you intended though personally I find

<a href="javascript:void(0)"
onclick="window.open('../../SomePathTo/script2.php?VariableName=<?=$variable?>',
'WinName','toolbar=no,location=no,directories=no,s
tatus=no,menubar=no,scrollbars=yes,resizable=yes,c
opyhistory=no,width=350,height=400')">
<font size='-1' face='Arial,Helvetica,Univers,Zurich BT,sans-serif'>Readable Link Text</font></a>

a lot easier as you dont need to escape all the quotes correctly (which may have lead to your error as it happens).

HTH,

Dai

Doug Calli
08-08-2003, 03:08 PM
That did it!

Not the escapes but the correct syntax <?=$variable?>

Thanks allot! :D

Now I have to go back and do what I orignally wanted but hey,... It's a learning thing. ;)

Edit:
Re: echo's - It's how I have my page setup, at the
end of the script it echo's the final work of the script.
Does that make sense?
It's how I was shown by another coder, is there a better
or another way I should look at?

Thanks again, DC

DaiWelsh
08-09-2003, 06:14 AM
That approach can work certainly - it is in effect a form of manual buffering of the output and can make life easier in some instances such as outputting headers half way through page processing.

Personally I find code written this way a lot harder to read and especially to debug, but that is me.

Also, I suspect this would be a performance drag as the php processor is handling the whole output, whereas interspersing php code with straight html means the php processor can ignore everything outside of <? ?>. It is similar to using single quotes rather than double quotes for literal strings so that the processsor does not have to scan the string for variable insertions (something many people do not realise the benefit of).

However I dont have any evidence to support this performance loss, it is just based on my own intuition. Also it may not be an issue if you are working on a low load or non performance critical site.

I think everyone has to find their own style and I should not be too critical of other peoples, just personally I am not a fan.

HTH,

Dai

Doug Calli
08-09-2003, 10:50 AM
Originally posted by DaiWelsh
this would be a performance drag as the php processor is handling the whole output

I'm sure you're right on this, thanks for the tip!

BTW: I've rewritten my code to use the popup window and it works great, thanks again!

DC