SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,530
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    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...
    HTML Code:
    	<!-- 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

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    I don't want to just default to a value in the main list because that would be PRESUMPTUOUS!!
    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".

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,530
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    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".
    Ha ha!


    Debbie

  4. #4
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    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:
    http://htmlhelp.com/reference/html40/olist.html

    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?

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,530
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    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!
    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

  6. #6
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    5,342
    Mentioned
    214 Post(s)
    Tagged
    5 Thread(s)
    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. )

    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.
    Don't be arrogant. Be kind to a koala that thinks it's a bear.

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,454
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    What about
    HTML Code:
    <option value="" selected="selected" disabled="true">--</option>

  10. #10
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    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.

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,454
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    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.

  12. #12
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,530
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Stomme Poes,

    You *never* cease to make me laugh uncontrollably?!


    Quote Originally Posted by Stomme poes View Post
    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.
    YOU ARE A NUT!!!!!!!


    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

  13. #13
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,530
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    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.
    I think that you have the best suggestion, Mittineague!

    Thanks,


    Debbie

  14. #14
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    Quote Originally Posted by debbie
    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.
    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.

  15. #15
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <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...elect-required
    Simon Pieters


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •