Results 1 to 5 of 5

Thread: Using id vs. name in an HTML form

  1. #1
    Join Date
    Sep 2008
    Location
    Midland, Texas
    Posts
    52
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Question Using id vs. name in an HTML form

    Does the "$_POST['searchtype']" works with the 'name = "searchtype" ' or could it be used with the 'id = "searchtype" ' attribute? Thanks in advance for your help.
    Last edited by xtiano77; 03-16-2009 at 01:16 AM.

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    It will only work with name, but you can use both if you want. It makes no logical sense though. If you would like to, make sure there is no other element with the same id. Just to say, the id doesn't affect the outcome in any form or way.
    Last edited by magicyte; 03-16-2009 at 01:15 AM.

  3. #3
    Join Date
    Sep 2008
    Location
    Midland, Texas
    Posts
    52
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Thank you Chris for your prompt reply. I understand what you are saying about it not making sense. I was just trying to find out if it worked with the "id" attribute so I can write "Strict" XHTML if needed. Thanks again.

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    No, it doesn't work with the id attribute. Simple as that. I'd already said "It will only work with name", just to let you know.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Names are used as the names of the parameters, and may be non-unique (to allow for checkbox groups, radio button groups, and element arrays); IDs are used to refer to the element within the document (e.g. from Javascript), and must be unique.

    Probably you shouldn't be worrying about XHTML compatibility at the moment. IE doesn't yet support XHTML, so it is not feasible for most applications.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •