#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    13
    Rep Power
    0

    Dynamically Script JavaScript from PHP


    I'm trying to get my php to dynamically generate a javascipt menu system. The problem I have is that my PHP parser will not recognise the php code in the middle.

    <script language="JavaScript1.2" src="../coolmenus3.js">

    some Javascript stuff


    <?php
    if ($somePHPVariable)
    echo Javascript commands
    else
    echo other Javascript commands
    ?>

    More Javascript Stuff
    </script>

    I hope this made sense to someone out there.
    Last edited by FireBlade; February 24th, 2003 at 04:06 AM.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    13
    Rep Power
    0
    Well I figured it out eventually and learnt some things as well. I'm not sure why but if the parser reads
    <script language="JavaScript1.2" src="../coolmenus3.js">

    It will then Skip everything until </script> is found. Which is quite annoying when you want to put a <?PHP echo $something; ?> in the middle of it.

    So the work around was using the PRINT function:
    PHP Code:
    <?php

    PRINT "
    <script language="
    JavaScript1.2" src="../coolmenus3.js">

    some Javascript stuff
    "
    ;
    if (
    $somePHPVariable)
    echo 
    Javascript commands
    else
    echo 
    other Javascript commands

    PRINT "

    More Javascript Stuff
    </script>
    "
    ;
    ?>
    This seemed to echo out all the Javascript and allow me to dynamically modify the menu to be sent out.

IMN logo majestic logo threadwatch logo seochat tools logo