• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Stuff like this makes me want to pull my hair out. Simple drop down menu form.

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
View page source shows:

Code:
<b><h2>MAKE SURE THAT PHOTOGRAPHER IS CORRECT:</b></h2> 
<select name="photographer">
	<option value="Victor" selected="">Victor</option>
	<option value="Anthony" selected="selected">Anthony</option>
	<option value="Ana" selected="">Ana</option>
	<option value="Scott" selected="">Scott</option>
</select>

Why the hell then is Scott the pre-selected value?

http://www.w3schools.com/tags/att_option_selected.asp
 
Last edited:
Nevermind. Damn W3Schools. Code they gave was totally wrong. selected="selected" is wrong.

Should be simply:

Code:
<b><h2>MAKE SURE THAT PHOTOGRAPHER IS CORRECT:</b></h2> 
<select name="photographer">
	<option value="Victor">Victor</option>
	<option value="Anthony" selected>Anthony</option>
	<option value="Ana">Ana</option>
	<option value="Scott">Scott</option>
</select>
 
W3Schools is showing you the proper XHTML way of doing it. XHTML is a form of HTML that is also in XML form. The reason why your original way failed is because you added the selected="" to the unselected options. Browsers that don't see it as XHTML will interpret it to be equivalent to the HTML "selected". Since Scott was the last option marked "selected" it was the pre-selected option.
 
Just echoing what KB said. W3 schools wasn't wrong here, your code was.

Browser look for the existence of the selected tag, not for the value contained within. Proper HTML dictates that you always set it to SOME value.

Another example of this is the "checked" attribute in checkboxes.
 
Just echoing what KB said. W3 schools wasn't wrong here, your code was.

Browser look for the existence of the selected tag, not for the value contained within. Proper HTML dictates that you always set it to SOME value.

Another example of this is the "checked" attribute in checkboxes.

W3Schools definitely did not explain this part. I thought the browser looks for the existence of the value within. Otherwise why have anything in the quotations if it's not to toggle whatever it is on or off? So I had set my code as variable driven.

Code:
if $Photographer == "Victor" {
$toggle = "selected";
}
elseif $Photographer == "Anthony" {
$toggle = "selected";
}

...

echo'<select name="photographer">
	<option value="Victor" selected=".$toggle.">Victor</option>
	<option value="Anthony" selected=".$toggle.">Anthony</option>
	<option value="Ana" selected=".$toggle.">Ana</option>
	<option value="Scott" selected=".$toggle.">Scott</option>
</select>'

Basically no explanation was given. Now I have to wonder why do I have to have a value? Why can't I just have 'selected'?
 
Last edited:
You can have just selected - as long as you're writing HTML, not XHTML. It's perfectly valid in HTML according to the W3C specs and their markup validation service.

You have to use selected="selected" in XHTML - mainly because of it's XML heritage - but you should not be using XHTML.
 
Back
Top