0

Im trying to output a dropdown select menu from an array, and it all works fine, but the default option isnt working. Heres what ive got:

<?php
		$usertz = $user->$main["timezone"];

	foreach($timezonearray as $tz => $off)
	{
		echo "<option value='$tz'"; 
		if($tz == $usertz)
		{
			echo 'selected="selected"';
		}
		echo ">$tz";
		if(array_key_exists($tz, $timezonelabelarray))
		{
			echo " / ".$timezonelabelarray[$tz];
		}
		echo "</option>";
	}
	?>

$timezonearray, $timezonelabelarray, and $user are global vars on the server. $timezonearray is a list of timezones from GMT-11 to GMT+13. $timezonelabelarray is a name given to some of them (for example, GMT-5 is also EST). The value of $user->$main["timezone"] is the timezone that the user has selected that all their times be displayed in. This dropdown is supposed to display all the timezones, and default to the timezone that the user has selected to display. Everything works except for the default select. Any ideas?

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by jonathan96
0

simply echo word selected with space at line no 9 of your code
echo " selected "; //correct

DO NOT ASSIGN ANYTHING
echo 'selected="selected"' //incorrect

Edited by urtrivedi: n/a

0

Thanks for the reply :)

simply echo word selected with space at line no 9 of your code
echo " selected "; //correct

DO NOT ASSIGN ANYTHING
echo 'selected="selected"' //incorrect

if($tz == $usertz)
		{
			echo " selected ";		
		}

It looks like this now and still doesn't work.

0

i m changing your line no 11 of first post, to verify whether tz=usertimezone. check of space and character case in $tz/$usertz. You may also want you use $off variable.

echo ">$tz (TZ={$tz},   USERTZ={$usertz})";

Edited by urtrivedi: n/a

0

Hmmm...It appears that $usertz is blank...Thanks, thats good to know.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.