470,831 Members | 1,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,831 developers. It's quick & easy.

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
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.  
  3. function autoSubmit()
  4. {
  5.     var formObject = document.forms['theForm'];
  6.     formObject.submit();
  7. }
  8.  
  9. </script>
//php

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

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

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

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

<select name="province" onChange="autoSubmit();">
<option value="null">Province</option>

<?php

//POPULATE DROP DOWN MENU WITH PROVINCES

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

while($row = mysql_fetch_array($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_SITE_ID FROM SAMP_SITE WHERE Province = '$province' ";
$sites = mysql_query($sql);

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

?>

</select>

<?php

}

?>
<input type='image' src='searchedirt.bmp' onClick='submit'>
</form>[/PHP]
Mar 6 '07 #1
2 2611
ronverdonk
4,258 Expert 4TB
Can't see what the problem is except for

1. enclosing this
Expand|Select|Wrap|Line Numbers
  1.  $province = $site = null; //declare vars
  2.  
  3. if(isset($_GET["province"])) {
  4.     $province = $_GET["province"];
  5. }
  6. if(isset($_GET["site"]) && is_numeric($_GET["site"])) {
  7.     $city = $_GET["site"];
  8. }
  9.  
within <?php and ?> tags.

2. removing the double quote in statement
Expand|Select|Wrap|Line Numbers
  1. <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:
Mar 6 '07 #2
Can't see what the problem is except for

1. enclosing this
Expand|Select|Wrap|Line Numbers
  1.  $province = $site = null; //declare vars
  2.  
  3. if(isset($_GET["province"])) {
  4.     $province = $_GET["province"];
  5. }
  6. if(isset($_GET["site"]) && is_numeric($_GET["site"])) {
  7.     $city = $_GET["site"];
  8. }
  9.  
within <?php and ?> tags.

2. removing the double quote in statement
Expand|Select|Wrap|Line Numbers
  1. <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.
Mar 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by KK | last post: by
2 posts views Thread by hemanth.singamsetty | last post: by
4 posts views Thread by simon.cigoj | last post: by
4 posts views Thread by TycoonUK | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.