954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

setting default value to DropDown Menu using PHP

Hello,
I have a page say 03.htm where I have a hyperlink to notes.php .In notes.php I have a dropdown menu which has a collection of all pages from 01-20 ,where I have to choose between 01-20.What I want is that since I clicked hyperlink from 03.htm the dropdown menu must set its default selected value to 03.If I clicked hyperlink from 10.htm the dropdown menu in notes.php must set its default selected value to 10 such that user does not have to select the page number in the drop down menu .. and its automatically done by default..Please help !
Thanks ..

vaish.rajan
Newbie Poster
4 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 
<?
$pages = array();
for($i = 0; $i < 20; $i++)
{
	$page = $i;
	if($page < 10)
	{
		$page = "0" . $page;
	}
	$pages[] = $page;
}
?>

<select name="selPage" id="selPage">
	<?
	foreach($pages as $page)
	{
	?>
		<option<?
		if(strpos($_SERVER['HTTP_REFERER'], $page . ".htm") !== false)
		{
			echo ' selected="selected"';
		}
		?> value="<? echo $page . ".htm"; ?>"><? echo $page . ".htm"; ?></option>
	<?
	}
	?>
</select>
R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You