Default Value for Dropdown?

What is the proper way to set a default value for a Dropdown?

Here is the code that I currently have…


	<!-- Gender -->
	<label for="gender">Gender:</label>
	<select id="gender" name="gender">
		<option value="">--</option>
		<option value="F">Female</option>
		<option value="M">Male</option>
	</select>

I don’t want to just default to a value in the main list because that would be PRESUMPTUOUS!!

But then again, but having a choice that yields a zero-length string, that could cause problems in my database and thus require that I have to write more code to handle things?!

Suggestions?

Thanks,

Debbie

Not really. It could be a good way to encourage the user to make a choice—out of embarrassment or pride—especially if the default value is something like “Hermaphrodite”. :shifty:

Ha ha!

Debbie

Remember the rule – ALL USER INPUT IS SUSPECT – so you should be running a test server side to see if a valid value is sent or not ANYWAYS… as such there’s no “extra code” involved as you should have that in place anyways!

Also, you should probably include the option “don’t say” and make that the default, some wacko’s out there are offended by even being asked.

Though you are asking in the HTML forums, so I assume you are asking about the SELECTED property.

<option selected> – html
<option selected=“selected”> – XHTML

Which chooses which one to fill in the input with by default… When in doubt, go to a decent reference:

Honestly, I think most people writing pages need to stop, take the time to read ALL of that site, then continue.

Oh, and little tip, since value defaults to the content of the tag for OPTION, why not just send ‘male’ or ‘female’ to the server and handle it that way?

As usual, you are correct DeathShadow. (It’s late here!)

Also, you should probably include the option “don’t say” and make that the default, some wacko’s out there are offended by even being asked.

Interesting point, and material for another thread in my mind.

On that topic I am thinking of having a “Show/Hide” checkbox next to all optional fields in the “Change Details” form.

Though you are asking in the HTML forums, so I assume you are asking about the SELECTED property.

<option selected> – html
<option selected=“selected”> – XHTML

No, I meant what do I do if I do NOT want to pre-fill a field like Gender with “Female”.

Oh, and little tip, since value defaults to the content of the tag for OPTION, why not just send ‘male’ or ‘female’ to the server and handle it that way?

You lost me?!

I don’t want to pre-fill Gender with “Female”, because you - as a “Male” - might not like that. Or, you - as a “Male” - might not notice it since it is pre-filled and end up registering as a “Female”?!

I’m used to seeing dropdowns default to “” and thus forcing this User to make a choice, but I wasn;t sure what the right way is from a design standpoint.

Or are you saying leave it blank like I have it and then have my PHP throw up a “Gender must be Male or Female” message if they do not make a choice?

Debbie

I believe it’s something with PHP you’re looking for.

Here is an example:

http://www.tizag.com/phpT/examples/formex.php
http://www.tizag.com/phpT/examples/formfinale.php
http://www.tizag.com/phpT/examples/formexample.php

I believe you have your answer in there as far as the gender options go.

Here’s something more about PHP and HTML forms:

http://myphpform.com/

http://www.phpf1.com/tutorial/php-form.html

http://www.html-form-guide.com/html-form/html-form-input.html

http://www.html-form-guide.com/php-form/php-form-tutorial.html

If you are allowing user not to select gender, you can make an check box to allow “not to reveal gender”. I saw a site allow me to do that, but i don’t quite sure what or which web site.
Thus you don’t need to check whether the gender is null or not, and the check is quite straight forward too. Check the check box, if null, show error. If not null, you even don’t need to check the error.

Sent from my GT-I5500 using Tapatalk

I’ve seen “Prefer not to say” as an option. (Although my favourite was a paper form with the option “Don’t know” also included. :eek2:)

If you order all your drop-downs alphabetically, then “female” naturally comes first, and your male visitors have no reason to feel irked because you are keeping to a logical scheme.

What about

<option value="" selected="selected" disabled="true">--</option>

Selected and disabled?

I’m picky with disabled, it may not be read out to the AT layer. You could just have it selected and let the back-end (or even front-end) validate that as an error and give the appropriate message.

Back when I was doing our insurance forms, we had some selects that people were skipping over (leaving the valid but usually-not-correct-for-their-other-info “0”) so the boss made us choose the first option as value=“------” so people not selecting something got an error message, which prompted them to make a choice.

That was a bad solution to a usability problem. The problem was, people see a value in a dropdown and deep down inside they hope they don’t have to choose something other than default. (btw this is generally not a problem with gender: it’s early in a form usually, people are fresh, and defaults aren’t usually true or usable in the Personal Info sections). If you need an error message to get people to fill in an input, you’re doing something wrong, and we certainly were.
What we should have done is changed to something other than a select input.

Anyway anyone who is offended by one gender option being default over the other is batsh*t insane and you don’t want them filling out your form anyways, even if they’re loaded and super-wealthy like Bruce Wayne. Stay away from them. They will eat your babies.
Someone needing an option other than Male and Female, though, sounds pretty normal to me (or, I just happen to know too many trans-gendered and whatever people?). But selects need defaults to show, and frankly having ------ as the gender option showing by default may psychologically hint to users that “you don’t need to fill this one in”. If that’s an option, then why make people bother seeing it? Remove the question if it’s not important.

Smartest thing my old boss ever did was removing the question “What colour is your car?” from the insurance forms. The colour affecting nothing, so why make the user do more work? People hate filling out forms. Keep them short and sweet. Or at least short.

Yes, I think a pair of radio buttons (with maybe a third for “no thanks”) would be better here. Not like it’s being dynamically filled with values from a database.

Stomme Poes,

You never cease to make me laugh uncontrollably?! :lol:

YOU ARE A NUT!!! :rofl:

Smartest thing my old boss ever did was removing the question “What colour is your car?” from the insurance forms. The colour affecting nothing, so why make the user do more work?

That is actually wrong…

Actuaries shows that people with certain car colors (e.g. red) are much more likely to drive fast and get into accidents.

People hate filling out forms. Keep them short and sweet. Or at least short.

True, but this is also a User Profile, so if they are there, I would hope they would be interested in filling things out. It is not compulsory.

Debbie

I think that you have the best suggestion, Mittineague! :tup:

Thanks,

Debbie

[ot]

Red (and yellow) catches cops’ eyes better than bland, so they get pulled over more, ticketed more, and seen more. But it didn’t affect what you paid for our insurance. Your claims and damage did.

Now age is another indicator with similar evidence behind it (drivers under age 25 have more accidents than over that age), and that is used to determine price. Mostly here because age is always used by all insurers and the bonus/malus tables (years used to determine a point system based on damage-free driving years) are based on the life insurance tables. We suspected colour may have been used to add an extra to the premium by some of our competitors, but for us it mattered too little to be worth a rise in premiums, which of course we’re all fighting to get customers based on that.

Plus, while my own driving doesn’t go from normal to bad just because I switch from a bland car to a red one, but a 23-year-old will drive like a 23-year-old regardless of car they get into. So since we’re using the driver’s stats to set rates, that still seems closer to fair as well (we didn’t do stuff like discount for alarms, seat-belt use or good grades, which I know is more and more common in the US… I like those too).

People filled out our forms in order to

  1. get a quote (and colour of the vehicle never affected the price)
  2. buy the insurance

If we are asking users for the minimal necessary information to tell them how much the type of insurance they want will cost, we ask them only those questions. Since colour never affects the price, the boss removed it. It still ended up being a long form, but every little bit helped.

Certain brands of scooters also got stolen more (and theft was the biggest claim for scooters, more than accidents), but while we had an optional field for scooter info (optional because we had no extra databases of stuff for per-brand for scooters but did for cars), we didn’t change the price based on whether you drove Aprilia or Piaggio or Honda. Instead, we leveled out that risk by having as many scooters insured as we could get. Volume ended up being more worthwhile than charging more for the more popular scooters.[/ot]

<label for="gender">Gender:</label>
	<select id="gender" name="gender" required>
		<option value="">--</option>
		<option value="F">Female</option>
		<option value="M">Male</option>
	</select>

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#attr-select-required