Jump to content

Whats echo 'selected'?


deansaddigh

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990822
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/187681-whats-echo-selected/#findComment-990850
Share on other sites

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.