#1
  1. No Profile Picture
    Gone PHP Crazy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    393
    Rep Power
    12

    writing Javascript with PHP


    I have a javascript code that I want to generate when a submit button is clicked. The javascript code is this:
    Code:
    <script type="text/javascript">
    document.product_form.pdt_image_path.value="products/" + $selected_dir + "/";
    </script>
    I tried to generate that code with php but I get an error like so:

    'document.product_form.pdt_image_path' is null or not an object
    Here is the code I generated in php:
    PHP Code:
        echo "<script type=\"text/javascript\">";
        echo 
    'document.product_form.pdt_image_path.value="products/" + $selected_dir + "/";';
        echo 
    "</script>"
    $selected_dir is the dynamically generated variable which holds a folder name. document.product_form.pdt_image_path is a form field which exists on the page. Any idea whats wrong in my code ?
    visit http://www.techsatcomputers.com
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Jun 2002
    Location
    Washington, DC
    Posts
    2,692
    Rep Power
    22
    EDIT::
    Vb messes up the escapes - here it is without tags

    echo( '<script type="text/javascript">' . "\n" );
    echo( 'document.product_form.pdt_image_path.value="products/\'+' . $selected_dir . '+\'/";' . "\n" );
    echo( '</script>' . "\n" );

    Also - 'document.product_form.pdt_image_path' is null or not an object is a jscript error and not php error...
    Last edited by jpenn; April 28th, 2003 at 01:25 AM.
    ~ Joe Penn

IMN logo majestic logo threadwatch logo seochat tools logo