Jump to content

Drop down menu not keeping value


BillyMako

Recommended Posts

When i select something from the drop down list it is not passing it to the next page.

 

              <tr><?php @$suburb=$_GET['suburb']; ?>
                <td class="main"><?php echo ENTRY_SUBURB; ?></td>
                <td class="main"><?php 

			echo "<select name='suburb'><option value='$suburb'>Select Suburb</option>"; // onchange=\"reload(this.form)\"
while($pop = mysql_fetch_array($query)) { 
if($pop['postcode']==@$suburb){
echo  "<option value='$pop[postcode]'>$pop[suburb]</option>";
}else{
echo "<option selected value='$suburb'>$pop[suburb]</option>";}
}

echo "</select>";

			 ?> *

Link to comment
https://forums.phpfreaks.com/topic/120483-drop-down-menu-not-keeping-value/
Share on other sites

So...

 

  • Are you using method="get"?
  • Are those error suppressors in front of "@$suburb". Why are you doing that?

 

Now...

 

It might be that in the following code:

 

<?php
if($pop['postcode']==@$suburb){
echo  "<option value='$pop[postcode]'>$pop[suburb]</option>";
}else{
echo "<option selected value='$suburb'>$pop[suburb]</option>";
}
?>

 

You are telling it to print out an ordinary option WHEN they match. Shouldn't your code be:

 

<?php
if($pop['postcode']==$suburb){
echo "<option selected value='$suburb'>{$pop['suburb']}</option>";}
}else{
echo  "<option value='{$pop[postcode]}'>{$pop['suburb']}</option>";
}
?>

It's cut down now, still works but wont hold the value when form is submitted.????

 

 

echo"Suburb: ";
			echo "<select name='suburb'><option value='$suburb'>Select Suburb</option>"; // onchange=\"reload(this.form)\"
while($pop = mysql_fetch_array($query)) { 
echo "<option value='$pop[postcode]'>$pop[suburb]</option>";
}

echo "</select>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.