help: Creating popup from in php file using JS.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

help: Creating popup from in php file using JS.

Post by camarosource »

I have a HTML form: http://www.camarosource.ca/decoders/eng_vin_decoder/

Upon pressing "Decode" a PHP file reads the code entered in the field and displays a HTML template depending on the info they entered: http://www.camarosource.ca/decoders/eng ... 7-1969.htm

The code used to do this is:

Code: Select all

$serial_decode = $serial;
$file = "../../../decoders/eng_vin_decoder/1967-1969.htm";
$read = fopen($file, "r");
$content = fread($read, filesize($file));
$content = ereg_replace("{VIN}", $VIN, $content);
$content = ereg_replace("{make}", $make, $content);
$content = ereg_replace("{make_decode}", $make_decode, $content);
$content = ereg_replace("{model_year}", $model_year, $content);
$content = ereg_replace("{model_year_decode}", $model_year_decode, $content);
$content = ereg_replace("{plant}", $plant, $content);
$content = ereg_replace("{plant_decode}", $plant_decode, $content);
$content = ereg_replace("{serial}", $serial, $content);
$content = ereg_replace("{serial_decode}", $serial_decode, $content);
echo $content;
I would like for it to display this http://www.camarosource.ca/decoders/eng ... 7-1969.htm is a NEW window as a Presized window that is 475 X 275 pixels.

So to the views side, they enter info in the form, press "Decode", and a pre-size window pops up with the contents replacing the {Variables}.

Problem is, I can't figure out how to get the pop up to work with errors and still replacing the {Variables} in the file.

I tried the following to make the popup but it pops the window open, (error on the first page), and the variables in the html file are not replacing"

Code: Select all

$serial_decode = $serial;
$file = "../../../decoders/eng_vin_decoder/1967-1969.htm";
$read = fopen($file, "r");
$content = fread($read, filesize($file));
$content = ereg_replace("{VIN}", $VIN, $content);
$content = ereg_replace("{make}", $make, $content);
$content = ereg_replace("{make_decode}", $make_decode, $content);
$content = ereg_replace("{model_year}", $model_year, $content);
$content = ereg_replace("{model_year_decode}", $model_year_decode, $content);
$content = ereg_replace("{plant}", $plant, $content);
$content = ereg_replace("{plant_decode}", $plant_decode, $content);
$content = ereg_replace("{serial}", $serial, $content);
$content = ereg_replace("{serial_decode}", $serial_decode, $content);
$content = ereg_replace("'", '"', $content);
echo "<html><head>";
echo "<script language='javascript'>";
echo "function popup() &#123;";
echo "pop = window.open('../../../decoders/eng_vin_decoder/1967-1969.htm', 'title', 'HEIGHT=475,WIDTH=275');";
echo "pop.write('<html><head></head><body>hi there</body></html>');";
echo "pop.close();";
echo "&#125;";
echo "</script>";
echo "</head><body onload='popup()'></body></html>";

TEST IT OUT FOR YOURSELF: (WORKING NO POPUP)

http://www.camarosource.ca/decoders/eng_vin_decoder/

Select "1967"
Enter "17n123456"
Press "decode"

WORK perfectly when NOT a popup

NOW: (POPUP WORKS, ERRORS, BLANK PAGE, NO VARIABLES BEING REPLACED)

http://www.camarosource.ca/decoders/eng ... index2.htm

Select "1967"
Enter "17n123456"
Press "decode"

You'll notice the popup works. But the variables are NOT being replaced like they should, AND there is a javascript error on the first plage which turns to a white page.

The error: "Line 1:
"Chars: 121
"Error: Object doesn't support this property or method.
"Code: 0
"URL: http://www.camarosource.ca/php/decoders ... coder2.php

PLEASE HELP! THANKS
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

basically, you aren't passing the variables to the pop-up window.

remove

Code: Select all

pop.write('<html><head></head><body>hi there</body></html>');
pop.close();
to get rid of the error you are getting on the next page.

i think if on this line

Code: Select all

pop = window.open('../../../decoders/eng_vin_decoder/1967-1969.htm', 'title', 'HEIGHT=500,WIDTH=300');
change it to

Code: Select all

pop = window.open('../../../decoders/eng_vin_decoder/1967-1969.htm?FORM_YEAR=<? use php to put the value here ?>&FORM_VIN=<? use php to put the value here ?>', 'title', 'HEIGHT=500,WIDTH=300');
should work

Mark
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

Any suggests as to how to insert that PHP into the javascript section?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you should really try and figure this out for yourself, this is simple stuff.

Anyway, here goes

Code: Select all

pop = window.open('../../../decoders/eng_vin_decoder/1967-1969.htm?FORM_YEAR=<? echo $_POST&#1111;'FORM_YEAR']; ?>&FORM_VIN=<? echo $_POST&#1111;'FORM_VIN'];  ?>', 'title', 'HEIGHT=500,WIDTH=300');
Mark
Post Reply