Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Thanked 0 Times in 0 Posts


    hi! Can u please tell me whats wrong with my codes cause it doesn't work and I don't see where I went wrong.I have a page with two select fields where the second select field is populated with the values depending on the selection made in the first field.And this page refers to a php page which I refered it as a javascript page as shown below

    <title>Chained Selects</title>
    <script language="javascript" src="chainedselects.js"></script>
    <script type="text/javascript" src="reference.php"></script>
    <body onload="initListGroup('vehicles', document.forms[0].make, document.forms[0].type, document.forms[0].model, 'cs')">
    <table align="center"><tr>
    <td>Select a vehicle:&nbsp;</td>
    <td><select name="make" style="width:160px;"></select></td>
    <td><select name="type" style="width:160px;"></select></td>
    <td><input type="button" value="Reset" onclick="resetListGroup('vehicles')">
    The values to be filled in these select fields are obtained from reference.php which runs javascript codes as shown below
    PHP Code:
    var disable_empty_list=true;<br>

    addListGroup(\"vehicles\", \"car-makers\");<br>

    addOption(\"car-makers\", \"Select vehicle\", \"\", \"\", 1); <br>
    addList(\"car-makers\", \"Toyota\", \"Toyota\", \"Toyota\");<br>
    addList(\"car-makers\", \"Nissan\", \"Nissan\", \"Nissan\");<br>

    addOption(\"Toyota\", \"Select maker\", \"\", \"\", 1);<br> 
    addList(\"Toyota\", \"\");<br>
    addList(\"Toyota\", \"Hilux\");<br>
    addList(\"Toyota\", \"Land cruser\");<br>

    addOption(\"Nissan\", \"select maker\", \"\", \"\", 1);<br> 
    addList(\"Nissan\", \Safari\");<br>
    addList(\"Nissan\", \"Hard body\");<br>
    addList(\"Nissan\", \"Terrano\");
    Whats wrong with this reference.php page?

  2. #2
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Thanked 18 Times in 18 Posts
    The "<br>"s in your PHP don't have to be there.
    And, correct me if I'm wrong, but shouldn't the header say, "text/javascript"?

  3. #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Denver, Colorado USA
    Thanked 408 Times in 399 Posts
    Your browser should have been indicating errors (line numbers/character positions) in the javascript.

    To start with <br> is not valid javascript. Remove all of them in reference.php.

    The following line is missing a double-quote -

    addList(\"Nissan\", \Safari\");
    The header() statement is not necessary.

    And I recommend using the HEREDOC syntax so that you don't need to do things like escape all the double-quotes (which is probably how the double-quote got lost.) The following worked for me -

    PHP Code:
    echo <<<EOT
    var disable_empty_list=true; 

    addListGroup("vehicles", "car-makers"); 

    addOption("car-makers", "Select vehicle", "", "", 1);  
    addList("car-makers", "Toyota", "Toyota", "Toyota"); 
    addList("car-makers", "Nissan", "Nissan", "Nissan"); 

    addOption("Toyota", "Select maker", "", "", 1);  
    addList("Toyota", ""); 
    addList("Toyota", "Hilux"); 
    addList("Toyota", "Land cruser"); 

    addOption("Nissan", "select maker", "", "", 1);  
    addList("Nissan", "Safari"); 
    addList("Nissan", "Hard body"); 
    addList("Nissan", "Terrano"); 
    If you copy/paste the above, make sure that the EOT; at the end has nothing else on the line with it. The forum software usually adds a space at the end of the line and this will prevent the code from working.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


Posting Permissions

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