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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.