#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    63
    Rep Power
    11

    php/mysql/javascript drop down menus


    i have a page that works great with dependent menus: a select from the first affects the choices in the second. however, now i need to generate the contents of the lists from mysql instead of hard coded.

    the courses currently are in a .js file with the syntax where A is the first menu and B is the second.:

    var listB = new DynamicOptionList("B","A")
    listB.addOptions("1", "Name1, "Value1", ... )
    listB.addOptions("2", "Name3, "Value4", ... )
    ...
    1 and 2 represent the options from the the first list so that if the user selects 1 then Name1 shows up in the second instead of Name3.

    I can write a routine that can build this javascript code with php and mysql, but how does that work when the select list has an onChange method that uses this .js file. If I use php to generate the code in my .js file, it is no longer a .js file so will the javascript functions still recognize it with a require() in the main page the lists are created? does this make sense? if you could lend me some help that would be much appreciated. thanks.
  2. #2
  3. Psycho Canadian
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jan 2001
    Location
    Canada
    Posts
    4,846
    Rep Power
    635
    I'm sorry I don't understand excatly what you mean, but from what I gather you are currently including (requiring) a .js file right? ie

    include('myjsfile.js');

    But now you want to dynamicly create that .js file right? But now you have say

    include('myjsfile.php');

    If I'm right a few things you can do:

    1. When you generate the code with php print it out withen <script language="javascript"> </script> tags should work the same as if it was in a .js file.

    2. Leave the file named .js (unless a javascript file can be named anything) and have apache parse .js files.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    63
    Rep Power
    11
    thanks for the info. i don't have control over the server, so am not sure they would allow me to alter the config file. i think i'll create a php page with a function that returns the necessary script i need and put it in the actual page between javascript tags (as you suggested). i hadn't actually thought of that - the easiest solution is one that is often overlooked - thanks!!

IMN logo majestic logo threadwatch logo seochat tools logo