Loading ...
Sorry, an error occurred while loading the content.
 

referecing input controls with names that have spaces

Expand Messages
  • alrodkin
    Hi, I am a newbie to Internet programming. I have some questions about spacing in HTML control names and subsequently being able to access these input
    Message 1 of 4 , Aug 7 12:59 PM
      Hi,

      I am a newbie to Internet programming. I have some questions about
      spacing in HTML control names and subsequently being able to access
      these input elements in JavaScript If you don't have time to read
      the whole message, the main question is can HTML form names have
      spaces in them and if so what is the syntax for accessing them using
      Javascript

      I have a Perl script which dynamically creates html and ultimately
      generates a form. The form contains dynamically generated radio
      buttons and select controls. The value of the radio value is the
      same name as the select control name but this is only way I get the
      name of the select controls because I know exactly how many radio
      buttons there are and I know the radio button name. (if unclear
      disregard:not crucial)

      Many of the select control names contain spaces. When I try to
      access them in JavaScript through the DOM it doesn't work. Can I
      use spaces in input control names.?

      I have tried to create a Javascript variable which has a value which
      contains spaces and then use this variable in another Javascript
      statement. For example;

      selectedSG = document.Allan.SGGroup[i].value;
      When I print selectedSG it returns the correct value.
      eg. 'Large Clothing Line'


      But then when I try to use selectedSG in my JavaScript to access the
      a select input it doesn't work:

      document.Allan.selectedSG.length

      I have tried to hard code the select control name and it works if
      the select name has no spaces: for example

      document.Allan.Fabric.length (where fabric is a select control
      name) and then I receive the correct length for the specific select
      control

      However if I try to hard code a select name that contains spaces it
      doesn't work, ie.

      document.Allan.another magnificent day.length

      Clearly this syntax is wrong but I've tried bracketing and single
      quotes around another magnificent day and it still doesn't work

      Thanks ahead,
      Larry
    • Pipe n1
      alert(document.all[ check this out ].value) please tellme if it
      Message 2 of 4 , Aug 8 1:01 PM
        <body>
        <input type=button name="check this out" value='kinda works'>
        <script>
        alert(document.all["check this out"].value)
        </script>
        </body>

        please tellme if it helped

        On 8/7/05, alrodkin <allanrodkin@...> wrote:
        >
        > Hi,
        >
        > I am a newbie to Internet programming. I have some questions about
        > spacing in HTML control names and subsequently being able to access
        > these input elements in JavaScript If you don't have time to read
        > the whole message, the main question is can HTML form names have
        > spaces in them and if so what is the syntax for accessing them using
        > Javascript
        >
        > I have a Perl script which dynamically creates html and ultimately
        > generates a form. The form contains dynamically generated radio
        > buttons and select controls. The value of the radio value is the
        > same name as the select control name but this is only way I get the
        > name of the select controls because I know exactly how many radio
        > buttons there are and I know the radio button name. (if unclear
        > disregard:not crucial)
        >
        > Many of the select control names contain spaces. When I try to
        > access them in JavaScript through the DOM it doesn't work. Can I
        > use spaces in input control names.?
        >
        > I have tried to create a Javascript variable which has a value which
        > contains spaces and then use this variable in another Javascript
        > statement. For example;
        >
        > selectedSG = document.Allan.SGGroup[i].value;
        > When I print selectedSG it returns the correct value.
        > eg. 'Large Clothing Line'
        >
        >
        > But then when I try to use selectedSG in my JavaScript to access the
        > a select input it doesn't work:
        >
        > document.Allan.selectedSG.length
        >
        > I have tried to hard code the select control name and it works if
        > the select name has no spaces: for example
        >
        > document.Allan.Fabric.length (where fabric is a select control
        > name) and then I receive the correct length for the specific select
        > control
        >
        > However if I try to hard code a select name that contains spaces it
        > doesn't work, ie.
        >
        > document.Allan.another magnificent day.length
        >
        > Clearly this syntax is wrong but I've tried bracketing and single
        > quotes around another magnificent day and it still doesn't work
        >
        > Thanks ahead,
        > Larry
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >


        [Non-text portions of this message have been removed]
      • Jon Stephens
        Hi Allan, Either (a) Don t use spaces or (b) Use associative array notation, e.g. document.Allan.elements[ another magnificent day ].length or (c) Use the W3C
        Message 3 of 4 , Aug 8 6:21 PM
          Hi Allan,

          Either

          (a) Don't use spaces

          or

          (b) Use associative array notation, e.g.

          document.Allan.elements["another magnificent day"].length

          or

          (c) Use the W3C DOM method getElementsByName():
          document.getElementsByName("another magnificent day").length.

          or

          (d) Shoot the guy who wrote the Perl script - he should freaking know better.
          (Like it's hard to replace spaces with underscores, right.)

          :)




          > Message: 2
          > Date: Sun, 07 Aug 2005 19:59:10 -0000
          > From: "alrodkin" <allanrodkin@...>
          > Subject: referecing input controls with names that have spaces
          >
          > Hi,
          >
          > I am a newbie to Internet programming. I have some questions about
          > spacing in HTML control names and subsequently being able to access
          > these input elements in JavaScript If you don't have time to read
          > the whole message, the main question is can HTML form names have
          > spaces in them and if so what is the syntax for accessing them using
          > Javascript
          >
          > I have a Perl script which dynamically creates html and ultimately
          > generates a form. The form contains dynamically generated radio
          > buttons and select controls. The value of the radio value is the
          > same name as the select control name but this is only way I get the
          > name of the select controls because I know exactly how many radio
          > buttons there are and I know the radio button name. (if unclear
          > disregard:not crucial)
          >
          > Many of the select control names contain spaces. When I try to
          > access them in JavaScript through the DOM it doesn't work. Can I
          > use spaces in input control names.?
          >
          > I have tried to create a Javascript variable which has a value which
          > contains spaces and then use this variable in another Javascript
          > statement. For example;
          >
          > selectedSG = document.Allan.SGGroup[i].value;
          > When I print selectedSG it returns the correct value.
          > eg. 'Large Clothing Line'
          >
          >
          > But then when I try to use selectedSG in my JavaScript to access the
          > a select input it doesn't work:
          >
          > document.Allan.selectedSG.length
          >
          > I have tried to hard code the select control name and it works if
          > the select name has no spaces: for example
          >
          > document.Allan.Fabric.length (where fabric is a select control
          > name) and then I receive the correct length for the specific select
          > control
          >
          > However if I try to hard code a select name that contains spaces it
          > doesn't work, ie.
          >
          > document.Allan.another magnificent day.length
          >
          > Clearly this syntax is wrong but I've tried bracketing and single
          > quotes around another magnificent day and it still doesn't work
          >
          > Thanks ahead,
          > Larry
        • Tim Sabin
          document.all only works in IE. I would 1) use id instead of name, 2) replace spaces with, say, underscores, 3) use document.getElementById (name) . --Tim Sabin
          Message 4 of 4 , Aug 9 5:24 AM
            document.all only works in IE. I would 1) use id instead of name, 2)
            replace spaces with, say, underscores, 3) use document.getElementById
            (name) .

            --Tim Sabin


            > <body>
            > <input type=button name="check this out" value='kinda works'>
            > <script>
            > alert(document.all["check this out"].value)
            > </script>
            > </body>
            >
            > please tellme if it helped
            >
            > On 8/7/05, alrodkin <allanrodkin@...> wrote:
            > >
            > > Hi,
            > >
            > > I am a newbie to Internet programming. I have some questions about
            > > spacing in HTML control names and subsequently being able to access
            > > these input elements in JavaScript If you don't have time to read
            > > the whole message, the main question is can HTML form names have
            > > spaces in them and if so what is the syntax for accessing them using
            > > Javascript
            > >
            > > I have a Perl script which dynamically creates html and ultimately
            > > generates a form. The form contains dynamically generated radio
            > > buttons and select controls. The value of the radio value is the
            > > same name as the select control name but this is only way I get the
            > > name of the select controls because I know exactly how many radio
            > > buttons there are and I know the radio button name. (if unclear
            > > disregard:not crucial)
            > >
            > > Many of the select control names contain spaces. When I try to
            > > access them in JavaScript through the DOM it doesn't work. Can I
            > > use spaces in input control names.?
            > >
            > > I have tried to create a Javascript variable which has a value which
            > > contains spaces and then use this variable in another Javascript
            > > statement. For example;
            > >
            > > selectedSG = document.Allan.SGGroup[i].value;
            > > When I print selectedSG it returns the correct value.
            > > eg. 'Large Clothing Line'
            > >
            > >
            > > But then when I try to use selectedSG in my JavaScript to access the
            > > a select input it doesn't work:
            > >
            > > document.Allan.selectedSG.length
            > >
            > > I have tried to hard code the select control name and it works if
            > > the select name has no spaces: for example
            > >
            > > document.Allan.Fabric.length (where fabric is a select control
            > > name) and then I receive the correct length for the specific select
            > > control
            > >
            > > However if I try to hard code a select name that contains spaces it
            > > doesn't work, ie.
            > >
            > > document.Allan.another magnificent day.length
            > >
            > > Clearly this syntax is wrong but I've tried bracketing and single
            > > quotes around another magnificent day and it still doesn't work
            > >
            > > Thanks ahead,
            > > Larry
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > > Yahoo! Groups Links
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            >
            >
            > [Non-text portions of this message have been removed]
            >
            >
            >
            >
            >
            >
            >
            > Yahoo! Groups Links
            >
            >
            >
            >
            >
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.