naming syntax rules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    naming syntax rules

    I've just run into a weird quirk in IE where I had named form
    elements like this: 2-some_name. IE was using just the numeric part as
    an index in the form collection array. Boy, that took a while to figure out!

    So, what are the rules for names and ids? I had thought this was
    loosened up years ago.

    Jeff
  • Bart Van der Donck

    #2
    Re: naming syntax rules

    Jeff wrote:
       I've just run into a weird quirk in IE where I had named form
    elements like this: 2-some_name. IE was using just the numeric part as
    an index in the form collection array. Boy, that took a while to figure
    out!
    >
       So, what are the rules for names and ids? I had thought this was
    loosened up years ago.
    | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
    | be followed by any number of letters, digits ([0-9]), hyphens
    | ("-"), underscores ("_"), colons (":"), and periods (".").



    --
    Bart

    Comment

    • Henry

      #3
      Re: naming syntax rules

      On Apr 23, 3:12 pm, Bart Van der Donck wrote:
      Jeff wrote:
      > I've just run into a weird quirk in IE where I had named
      >form elements like this: 2-some_name. IE was using just the
      >numeric part as an index in the form collection array. Boy,
      >that took a while to figure out!
      >
      > So, what are the rules for names and ids? I had thought
      >this was loosened up years ago.
      >
      | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
      | be followed by any number of letters, digits ([0-9]), hyphens
      | ("-"), underscores ("_"), colons (":"), and periods (".").
      >
      http://www.w3.org/TR/REC-html40/types.html
      This is relevant for ID attributes, but NAME attributes are CDATA
      (except for the NAME attributes of META elements, which are NAME
      tokens) and so the preceding section of - REC-html40/types.html -
      defines their restrictions. ('2-some_name' may not be a viable ID but
      it is a valid NAME).

      Comment

      • Captain Paralytic

        #4
        Re: naming syntax rules

        On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.co mwrote:
        | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
        | be followed by any number of letters, digits ([0-9]), hyphens
        | ("-"), underscores ("_"), colons (":"), and periods (".").

        Interesting that it doesn't allow []

        Comment

        • Rik Wasmus

          #5
          Re: naming syntax rules

          On Wed, 23 Apr 2008 16:24:36 +0200, Captain Paralytic
          <paul_lautman@y ahoo.comwrote:
          On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.co mwrote:
          > | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
          > | be followed by any number of letters, digits ([0-9]), hyphens
          > | ("-"), underscores ("_"), colons (":"), and periods (".").
          >
          >
          Interesting that it doesn't allow []
          Not in ID's, but for PHP luckily in name attributes it's allowed :)
          From http://www.w3.org/TR/html4/strict.dtd:

          .....
          <!ELEMENT INPUT - O EMPTY -- form control -->
          <!ATTLIST INPUT
          %attrs; -- %coreattrs, %i18n, %events --
          type %InputType; TEXT -- what kind of widget is needed --
          name CDATA #IMPLIED -- submit as part of form --
          .....

          So, just CDATA in name attributes.
          --
          Rik Wasmus

          Comment

          • Jeff

            #6
            Re: naming syntax rules

            Henry wrote:
            On Apr 23, 3:12 pm, Bart Van der Donck wrote:
            >Jeff wrote:
            >> I've just run into a weird quirk in IE where I had named
            >>form elements like this: 2-some_name. IE was using just the
            >>numeric part as an index in the form collection array. Boy,
            >>that took a while to figure out!
            >> So, what are the rules for names and ids? I had thought
            >>this was loosened up years ago.
            > | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
            > | be followed by any number of letters, digits ([0-9]), hyphens
            > | ("-"), underscores ("_"), colons (":"), and periods (".").
            >>
            >http://www.w3.org/TR/REC-html40/types.html
            >
            This is relevant for ID attributes, but NAME attributes are CDATA
            (except for the NAME attributes of META elements, which are NAME
            tokens) and so the preceding section of - REC-html40/types.html -
            defines their restrictions. ('2-some_name' may not be a viable ID but
            it is a valid NAME).
            Oddly, in practice, it works the other way. All browsers I tested
            recognized the number first for IDs, IE failed for number first for form
            element name. Of course, IE's quirks are legion.

            With that said, I'll rewrite my IDs for this particular app to conform.

            Jeff

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: naming syntax rules

              Henry wrote:
              On Apr 23, 3:12 pm, Bart Van der Donck wrote:
              >Jeff wrote:
              >> I've just run into a weird quirk in IE where I had named
              >>form elements like this: 2-some_name. IE was using just the
              >>numeric part as an index in the form collection array. Boy,
              >>that took a while to figure out!
              >> So, what are the rules for names and ids? I had thought
              >>this was loosened up years ago.
              > | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
              > | be followed by any number of letters, digits ([0-9]), hyphens
              > | ("-"), underscores ("_"), colons (":"), and periods (".").
              >>
              >http://www.w3.org/TR/REC-html40/types.html
              >
              This is relevant for ID attributes, but NAME attributes are CDATA
              (except for the NAME attributes of META elements, which are NAME
              tokens) and so the preceding section of - REC-html40/types.html -
              defines their restrictions.
              Full ACK.
              ('2-some_name' may not be a viable ID but it is a valid NAME).
              ^^^^
              I think you meant `name' in the sense of "value of the `name' attribute of
              `form' elements or form controls" here, for the above definition makes it
              very clear that ID and NAME tokens have the same restrictions.


              PointedEars
              --
              Use any version of Microsoft Frontpage to create your site.
              (This won't prevent people from viewing your source, but no one
              will want to steal it.)
              -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: naming syntax rules

                Captain Paralytic wrote:
                On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.co mwrote:
                > | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
                > | be followed by any number of letters, digits ([0-9]), hyphens
                > | ("-"), underscores ("_"), colons (":"), and periods (".").
                >
                Interesting that it doesn't allow []
                It does not need to. Apparently you haven't been paying attention.


                PointedEars
                --
                Anyone who slaps a 'this page is best viewed with Browser X' label on
                a Web page appears to be yearning for the bad old days, before the Web,
                when you had very little chance of reading a document written on another
                computer, another word processor, or another network. -- Tim Berners-Lee

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: naming syntax rules

                  Rik Wasmus wrote:
                  [...] Captain Paralytic [...] wrote:
                  >On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.co mwrote:
                  >> | ID and NAME tokens must begin with a letter ([A-Za-z]) and may
                  >> | be followed by any number of letters, digits ([0-9]), hyphens
                  >> | ("-"), underscores ("_"), colons (":"), and periods (".").
                  >>
                  >Interesting that it doesn't allow []
                  >
                  Not in ID's, but for PHP luckily in name attributes it's allowed :)
                  [...]
                  Not in *all* `name' attribute *values*, but in most, including those
                  relevant here.


                  PointedEars
                  --
                  Anyone who slaps a 'this page is best viewed with Browser X' label on
                  a Web page appears to be yearning for the bad old days, before the Web,
                  when you had very little chance of reading a document written on another
                  computer, another word processor, or another network. -- Tim Berners-Lee

                  Comment

                  Working...