SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Burnaby, BC
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help: Creating popup from in php file using JS.

    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/.../1967-1969.htm

    The code used to do this is:
    Code:
    $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/.../1967-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:
    $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() {";
    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 "}";
    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/...der/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/decod...n_decoder2.php

    PLEASE HELP! THANKS

  2. #2
    SitePoint Member
    Join Date
    Aug 2003
    Location
    new york
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To post to a popup window, you have to add some javascript to the form's onsubmit event that opens the window.

    The new window then changes the form's target to point to itself and submits it. It's important that the new window do this because in many browsers the window won't be available to submit to right after it's open.

    Here's some code:

    Code:
    <form action="http://www.camarosource.ca/php/decoders/eng_vin_decoder/eng_vin_decoder2.php" method="POST" name="form1" onsubmit="postToPopup(); return false;">
    Then, you have to add this function somewhere in your page:

    Code:
    <script language="javascript" type="text/javascript">
        function postToPopup() {
            window.open("javascript:opener.document.form1.target='popup'; opener.document.form1.submit()", 'popup', 'width=475,height=275');
        }
    </script>
    HTH!

    --
    Aaron

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Burnaby, BC
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by boogs
    To post to a popup window, you have to add some javascript to the form's onsubmit event that opens the window.

    The new window then changes the form's target to point to itself and submits it. It's important that the new window do this because in many browsers the window won't be available to submit to right after it's open.

    Here's some code:
    Ok. My understanding is this.

    Replace in my FORM html

    Code:
    <form action="http://www.camarosource.ca/php/decod...in_decoder.php" method="POST">
    with

    Code:
    <form action="http://www.camarosource.ca/php/decod...n_decoder2.php" method="POST" name="form1" onsubmit="postToPopup(); return false;">
    Then add:

    Code:
     <script language="javascript" type="text/javascript"> function postToPopup() { window.open("javascript:opener.document.form1.target='popup'; opener.document.form1.submit()", 'popup', 'width=475,height=275'); } </script>
    in my 1967-1969.htm page (which is the file to be popped up with the variables inside)

    Then the code in my php file would be:

    Code:
    $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() {";
    echo "pop = window.open('../../../decoders/eng_vin_decoder/1967-1969.htm', 'title', 'HEIGHT=500,WIDTH=300');";
    echo "pop.close();";
    echo "}";
    echo "</script>";
    echo "</head><body onload='popup()'></body></html>";
    Correct or no? Cause doing this didn't seem to do anything new

  4. #4
    SitePoint Member
    Join Date
    Aug 2003
    Location
    new york
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, put the script in the file that does the popping up, not the file to be popped.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Burnaby, BC
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So it would be:

    $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 "<script language="javascript" type="text/javascript"> function postToPopup() { window.open("javascriptpener.document.form1.target='popup'; opener.document.form1.submit()", 'popup', 'width=475,height=275'); } </script>";

    ?

  6. #6
    SitePoint Member
    Join Date
    Aug 2003
    Location
    new york
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what? no, sorry, i thought i was pretty straight-foward. In the HTML file that has the form on it, you should have this code:

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Enter Engine VIN</title>
    
    <script>
        function postToPopup() {
            window.open("javascript:opener.document.form1.target='popup'; opener.document.form1.submit();", 'popup', 'width=475,height=275');
        }
    </script>
    
    </head>
    
    <body>
    
    <form action="http://www.camarosource.ca/php/decoders/eng_vin_decoder/eng_vin_decoder2.php" method="POST" name="form1" onsubmit="postToPopup(); return false;">
    <p align="center"><b>Enter Engine VIN:<br>(9 Digits)<br>
      <br>
    1. <select size="1" name="FORM_YEAR">
    <option selected value="-- Select Year --">-- Select Year --</option>
    <option>1967</option>
    <option>1968</option>
    <option>1969</option>
    <option>1970</option>
    <option>1971</option>
    <option>1972</option>
    <option>1973</option>
    <option>1974</option>
    <option>1975</option>
    <option>1976</option>
    <option>1977</option>
    <option>1978</option>
    <option>1979</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    </select><br>
    2.
      <input type="text" name="FORM_VIN" size="20"><br>
      <input type="submit" value="Decode" name="decode">
      <input type="reset" value="Clear" name="clear"></b></p>
    </form>
    
    </body>
    
    </html>
    And that would do it. Works for me anyway.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •