SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Drop down value

  1. #1
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop down value

    Hi in a drop down form selection is there a way to have a default value?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <select name="foo">
      <option value="foo">foo</option>
      <option value="default" selected="selected">default</option>
      <option value="bar">bar</option>
    </select>

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    as far as i remember, you don't have to say selected="selected", you can just have

    <select name="foo">
    <option value="foo">foo</option>
    <option value="default" selected>default</option>
    <option value="bar">bar</option>
    </select>


    anyway, whenever people do examples in PHP, they use the words "foo" and "bar". What do they mean, or are they just words which people see then use themselves?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They're just words that people have learnt to use as examples. They're not similar to any other words so it's easy to distinguish them.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    oh, cool. wierd words. Someone must have just got a random word maker to get that, they just sound weird!
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes you could just use selected and most browsers should understand it, but selected="selected" is the proper way to do it if you like to have your html validate.

    same with most attributes where you normally just typed them without a value
    checked="checked"
    disabled="disabled"
    etc...

    anyway, its a bit offtopic.

  7. #7
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall
    as far as i remember, you don't have to say selected="selected", you can just have

    <select name="foo">
    <option value="foo">foo</option>
    <option value="default" selected>default</option>
    <option value="bar">bar</option>
    </select>
    But that is invalid html, or at least invalid xhtml.

    Edit: Grrr, what clamcrusher said

  8. #8
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    im just making it easy. anyway, i think they're making it correct in the next html version
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #9
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall
    im just making it easy. anyway, i think they're making it correct in the next html version
    I doubt it. It's not even valid xml, which xhtml is supposed to be. Making it valid would kinda be a step backwards...

    But, extremely off topic

  10. #10
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    well, i like to be unconventional. Anyway, i don't see anything wrong with it. and if it works in HTML, it is correct or it wouldn't work!
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  11. #11
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall
    well, i like to be unconventional. Anyway, i don't see anything wrong with it. and if it works in HTML, it is correct or it wouldn't work!
    Uhh. it works because browsers still are backwards compatable at the moment to cater for sloppy coders such as yourself. selected="selected" is the correct way to implement it.

  12. #12
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall
    well, i like to be unconventional. Anyway, i don't see anything wrong with it. and if it works in HTML, it is correct or it wouldn't work!
    But it is, what I'd say, depricated. I don't know how long it'll work, but it's not valid in any of the recent html or xhtml versions. Just because it works doesn't mean you should use it.

    Sorry, I must persist...

  13. #13
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i mean like on a form how in the box it already have text in there so it reads from a database field is there a way to do that on a drop down form box?

  14. #14
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then read the value from the database, and as you are printing out the option elements, check if the value matches that from the database. If so, set that option to selected.

  15. #15
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my code how can i set it $def to the value for this:

    PHP Code:
    <select name="login">
    <
    option selected value="y">Yes</option><br>
    <
    option value="n">No</option>
    </
    select

  16. #16
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall
    ...anyway, whenever people do examples in PHP, they use the words "foo" and "bar". What do they mean, or are they just words which people see then use themselves?
    Its derived from Fubar - and is black humor for *ucked Up Beyond All Recognition. And was, part of a us pre-WW11 soldiers vocabulary, certainly was used a lot in nam.

    So its rather like this posting really, fubar.


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
  •