Results 1 to 3 of 3

Thread: Forms - name or id? [resolved]

  1. #1

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090

    Resolved Forms - name or id? [resolved]

    OK. Whenever I use forms that submit data to a PHP document I give the input element a name attribute so that I can get their values in the PHP. But I also know that name is being phased out and being replaced by id. The problem is that using id I can't get the values in the PHP code from the form. Is there a way to do this or should I still be using name attributes for this?
    Last edited by Acidic; Oct 8th, 2004 at 07:40 AM.
    Have I helped you? Please Rate my posts.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The name attribute is still completely valid and required on input elements.
    http://www.w3.org/TR/html401/interac...l#control-name

    The id attribute specifies the in-document id of an element, the name attribute specifies the name within the form and needs not be unique.

    It is, unfortunately, an illusion that keeps spreading that name should no longer be used for input names. This is wrong. What is true is that the id attribute should be used in parallel (and it doesn't need, in fact often can't, have the same value) so you can reference the form elements from within scripts, such as validation scripts. It is incorrect behaviour of Internet Explorer that the getElementById method finds elements by their name. It also often causes problems when a web author assigns only a name to an input, successfully obtains it via getElementById in IE and is then surprised that the script fails in other browsers. It is also the first thing I check whenever I have reason to suspect that it may be the source of the error. Finally, it's why my own function, bigebid, adds an additional check that the element REALLY has the required ID.
    Last edited by CornedBee; Oct 8th, 2004 at 05:58 AM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    ok, brillaint. Miss-conception sorted out now. Thanks.
    Have I helped you? Please Rate my posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width