refreshing drop down menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • millertime90
    New Member
    • Feb 2007
    • 3

    refreshing drop down menu

    Hi basically my problem is I have 2 drop down menus populated by my database the first populated by a field in the database and the 2nd populated with a relation to the value selected in the first and basically i'm just havin a problem refreshing the menus after i submit a value or refresh the page. My code is below:

    //javascript
    Code:
    <script language="JavaScript">
    
    function autoSubmit()
    {
        var formObject = document.forms['theForm'];
        formObject.submit();
    }
    
    </script>
    //php

    [PHP]
    $province = $site = null; //declare vars

    if(isset($_GET["province"]))
    {
    $province = $_GET["province"];
    }

    if(isset($_GET["site"]) && is_numeric($_GE T["site"]))
    {
    $city = $_GET["site"];
    }

    <form name="theForm" method="get">

    <select name="province" onChange="autoS ubmit();">
    <option value="null">Pr ovince</option>

    <?php

    //POPULATE DROP DOWN MENU WITH PROVINCES

    $sql = "SELECT DISTINCT Province FROM SAMP_SITE";
    $provinces = mysql_query($sq l);

    while($row = mysql_fetch_arr ay($provinces))
    {
    echo ("<option value=\"$row[Province]\" " . ($province == $row["Province"] ? " selected" : "") . ">$row[Province]</option>");
    }

    ?>

    </select>


    <br><br>

    <?php

    if($province != null)
    {

    ?>

    <select name="site"">
    <option value="null"></option>

    <?php

    //POPULATE DROP DOWN MENU WITH SITES GIVEN SELECTED PROVINCE

    $sql = "SELECT SiteName,SAMP_S ITE_ID FROM SAMP_SITE WHERE Province = '$province' ";
    $sites = mysql_query($sq l);

    while($row = mysql_fetch_arr ay($sites))
    {
    echo ("<option value=\"$row[SAMP_SITE_ID]\" " . ($city == $row["SAMP_SITE_ ID"] ? " selected" : "") . ">$row[SiteName]</option>");
    }

    ?>

    </select>

    <?php

    }

    ?>
    <input type='image' src='searchedir t.bmp' onClick='submit '>
    </form>[/PHP]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Can't see what the problem is except for

    1. enclosing this
    Code:
     $province = $site = null; //declare vars
    
    if(isset($_GET["province"])) {
        $province = $_GET["province"];
    }
    if(isset($_GET["site"]) && is_numeric($_GET["site"])) {
        $city = $_GET["site"];
    }
    within <?php and ?> tags.

    2. removing the double quote in statement
    Code:
    <select name="site"">
    It runs just fine at my server. At least it shows the second drop down.

    After hitting the image it does not do anything but that is because you don't have a 'submit' routine (as specified in your 'onclick=' in the last input statement).

    Ronald :cool:

    Comment

    • millertime90
      New Member
      • Feb 2007
      • 3

      #3
      Originally posted by ronverdonk
      Can't see what the problem is except for

      1. enclosing this
      Code:
       $province = $site = null; //declare vars
      
      if(isset($_GET["province"])) {
          $province = $_GET["province"];
      }
      if(isset($_GET["site"]) && is_numeric($_GET["site"])) {
          $city = $_GET["site"];
      }
      within <?php and ?> tags.

      2. removing the double quote in statement
      Code:
      <select name="site"">
      It runs just fine at my server. At least it shows the second drop down.

      After hitting the image it does not do anything but that is because you don't have a 'submit' routine (as specified in your 'onclick=' in the last input statement).

      Ronald :cool:

      Thanks Ronald for the lil quote error, but see it works right now but i want the menus to reload and show the null values once the page is refreshed or if they hit the back button after going to the submit routine. See right now if i hit the refresh button the menu will hold the last values i selected.

      Comment

      Working...