SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow "Chained Selects" Problem

    Hi,

    I'm trying to adapt the "Chained Selects" script at the moment, to use 2 instead of 3 drop down boxes.

    Although Mozilla Firefox detects no JS errors, when you select an item in the first drop down, nothing appears in the second. I'm sure that it's something to do with the config.js file and incorrect variables.

    I've renamed my config.js file to chainedselects.php, although this does not effect any links or references and the PHP script sends a JavaScript header.

    Web page using the form: http://www.cravecanada.com/index.php
    The config.js file: http://www.cravecanada.com/js/chainedselects.php
    The main JS file: http://www.cravecanada.com/js/chainedselects.js
    The instructions: http://www.dynamicdrive.com/dynamici...edselects.html

    Any help on figuring out this head scratcher would be appreciated.


  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a thought - Why is the config.js file called chainedselects.php ? Surley it should be called config.js.
    The PHP interpreter will be called to interpret chainedselects.php and will probably choke on it, as what is there in not valid PHP.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by swdev
    Just a thought - Why is the config.js file called chainedselects.php ? Surley it should be called config.js. The PHP interpreter will be called to interpret chainedselects.php and will probably choke on it, as what is there in not valid PHP.
    The file config.js was too static and could not do what I wanted it to do.
    chainedselects.php grabs both the provinces and towns out of a MySQL database and formats it into a JavaScript format. PHP scripts can be used to create and act like any file format including JavaScript, images, ZIP files and mp3 files. Renaming the file or using PHP to create a JavaScript file, is not an issue in any way.


  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the PHP code if you're interested, although the problem is to do with the JavaScript:

    PHP Code:
    <?
    header
    ('Content-type: application/x-javascript');
    include_once(
    "/path/to/functions.php");
    my_conn();
    $select_province mysql_query("SELECT * FROM towns GROUP BY field2 ORDER BY field3 asc");
    $num_select_province mysql_num_rows($select_province);

    ?>
    var hide_empty_list=true;

    addListGroup("canadianstates", "canadiantowns");

    addList("canadiantowns", "Select A State", "", "dummy-province", 1);
    <?
    for ($a=0$a <$num_select_province$a++)
    {
    $var_province mysql_fetch_array($select_province);
    print 
    "addList(\"canadiantowns\", \"".$var_province[field3]."\", \"".$var_province[field2]."\", \"".$var_province[field3]."\");\n";
    }
    ?>
    addList("dummy-province", "<- State Required", "", "dummy-town");
    addOption("dummy-town", "<- State Required", "");

    <?
    $select_province 
    mysql_query("SELECT * FROM towns GROUP BY field2 ORDER BY field3 asc");
    $num_select_province mysql_num_rows($select_province);
    for (
    $b=0$b <$num_select_province$b++)
    {
    $var_province mysql_fetch_array($select_province);
    print 
    "\naddOption(\"".$var_province[field2]."\", \"Select A Town (Optional)\", \"\");\n";
    $select_town mysql_query("SELECT * FROM towns WHERE field2 = '$var_province[field2]' ORDER BY town asc");
    $num_select_town mysql_num_rows($select_town);
    for (
    $c=0$c <$num_select_town$c++)
    {
    $var_town mysql_fetch_array($select_town);
    print 
    "addOption(\"".$var_town[field2]."\", \"".$var_town[town]."\", \"".$var_town[field1]."\");\n";
    }
    }
    print 
    "\n\n";
    ?>

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh well, I'll set up the navigation a different way.

    Thanks 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
  •