deansaddigh Posted January 8, 2010 Share Posted January 8, 2010 I have this code and i understand it all appart from the <option value = '' <? if ( $_SESSION['area'] == '' ){echo 'selected';}?>>Area</option> echo 'selected' What is that doing please. Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/ Share on other sites More sharing options...
oni-kun Posted January 8, 2010 Share Posted January 8, 2010 I have this code and i understand it all appart from the <option value = '' <? if ( $_SESSION['area'] == '' ){echo 'selected';}?>>Area</option> echo 'selected' What is that doing please. Well, listening to the logic: If the session variable 'area' contains nothing (empty string), than it will return the string 'selected'. So it will display: "Selected>Area" or similar into the html, the tag would make it selected. Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990822 Share on other sites More sharing options...
PravinS Posted January 8, 2010 Share Posted January 8, 2010 If the session variable "area" is blank then that option will be selected. Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990823 Share on other sites More sharing options...
deansaddigh Posted January 8, 2010 Author Share Posted January 8, 2010 Ok so just to clear it up, would it physically display the word 'selected' or would it just display the word area Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990839 Share on other sites More sharing options...
PHP Monkeh Posted January 8, 2010 Share Posted January 8, 2010 It would make that option in the drop-down menu selected by default. Though it's actually wrong as it should be selected="selected" for valid mark-up. Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990844 Share on other sites More sharing options...
monkeytooth Posted January 8, 2010 Share Posted January 8, 2010 selected="selected" is the proper way to do that.. But what it does is if that is contained in any given option that option is selected by default. example <select name="example"> <option value="var1">Option One</option> <option value="var2">Option Two</option> <option value="var3" selected="selected">Option Three</option> <option value="var4">Option Four</option> in the example, the option "Option Three" will be selected by default. Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990850 Share on other sites More sharing options...
deansaddigh Posted January 8, 2010 Author Share Posted January 8, 2010 Thanks guys i understand now. Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.