Jump to content

Drop Down that remembers your selection question....


SysAdm

Recommended Posts

Have a database with all 50 states in one column and another column that has 0 or 1 depending on if state is active.

 

Anyways, I have the code to generate the drop down menu with all the 50 states... works perfectly... now, when a user selects a state and hits SEARCH, I want their selection to stay selected, not default back to CHOOSE STATE....

 

Right now with this code, each entry in the Drop Down is SELECTED not just the one that is chosen....

 

function getStates($stateid)
{
global $state_tbl;
$allstates = q("select * from $state_tbl where state_is_valid=0 order by state_name");
while ($statenames = mysql_fetch_array($allstates))
{		
		$string.="<option value='$statenames[state_name]'";

		if (is_array($stateid))
			{	
			if (in_array($statenames[state_name],$stateid))
			$string.=" selected";
			}

		elseif ($stateid==$statenames[state_name])
			$string.=" selected";

	$lStateName = $statenames[state_name];		
	$string.=">$lStateName";
	$string.="</option>";
}

return $string;
}

 

Basically all I'm doing is trying to dynamically pull my data in a Drop Down and have it REMEMBER what the user selects what the page refreshes with a SEARCH.

 

Any help would be greatly appreciated and thanks in advance...

SysAdm

Hi,

 

Register the selected value in $_SESSION

 

while creating select dynamically simple add

 

if($statenames[state_name] == $_STESSION['state'])

{

    $string.="<option value='$statenames[state_name]' "selected">";

}else

{

  $string.="<option value='$statenames[state_name]'>";

}

 

Thanks

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.