Accessing hidden objects in a form

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

    Accessing hidden objects in a form

    Can anyone tell me the best way to access a hidden object in a form? I
    could use a hard-coded index to the elements of the form, but it's too
    easy to add something before the hidden object and mess up the
    indexing.

    For example:

    The form has a tagid of "myForm"
    The hidden object has a tagId of "myHiddenOb j"

    I can get the form elements by using
    var formElements = document.getEle mentById('myFor m').elements

    But there doesn't seem to be any way to do this:
    document.getEle mentById('myHid denObj')

    Assuming I have the elements as obtained above, none of these have
    worked for me either:

    formElements['myHiddenObj']
    formElements["myHiddenOb j"]
    formElements.my HiddenObj

    Anyone have an idea?
  • Java  script  Dude

    #2
    Re: Accessing hidden objects in a form

    craig.anderson@ vykor.com (Craig Anderson) wrote in message news:<eae5d3ca. 0407011603.e548 317@posting.goo gle.com>...[color=blue]
    > Can anyone tell me the best way to access a hidden object in a form? I
    > could use a hard-coded index to the elements of the form, but it's too
    > easy to add something before the hidden object and mess up the
    > indexing.
    >
    > For example:
    >
    > The form has a tagid of "myForm"
    > The hidden object has a tagId of "myHiddenOb j"
    >
    > I can get the form elements by using
    > var formElements = document.getEle mentById('myFor m').elements
    >
    > But there doesn't seem to be any way to do this:
    > document.getEle mentById('myHid denObj')
    >
    > Assuming I have the elements as obtained above, none of these have
    > worked for me either:
    >
    > formElements['myHiddenObj']
    > formElements["myHiddenOb j"]
    > formElements.my HiddenObj
    >
    > Anyone have an idea?[/color]



    document.getEle mentById is for accessing HTML elements with id's. If
    there is no ID, you will not see them. Unfortunately ID access is
    slow as the data is not efficiently indexed. Instead access through
    document.forms. ..

    Use form document.forms['formname'] and for the elements, I prefer to
    use the shortcut to the elements
    document.forms['formname']['formelemname']. This syntax works smoothly
    in Mozilla and IE.

    I generally assign the form to a global variable `oF` since I commonly
    access it more that once in my code
    (window.oF=docu ment.forms['formname']). I Then reference with the
    shortcut accessor oF['myHiddenObj'] to access form elements in. This
    syntax is the the most compact and should be efficient. I have not
    tested this syntax outside of Moz and IE though. For standards
    compliant access, use document.forms['formname'].elements['elemname'].

    There is one known bug in IE with the shortcut syntax above whereas if
    the form element names start with a number ( which it should not
    anyway ) IE cannot find them.

    For additional info check out javascript FAQ -


    JsD

    Comment

    • Ralph Snart

      #3
      Re: Accessing hidden objects in a form

      On 1 Jul 2004 17:03:44 -0700, Craig Anderson <craig.anderson @vykor.com> wrote:[color=blue]
      >Assuming I have the elements as obtained above, none of these have
      >worked for me either:
      >
      > formElements['myHiddenObj']
      > formElements["myHiddenOb j"]
      > formElements.my HiddenObj
      >
      >Anyone have an idea?[/color]

      document.forms['nameofform']['myHiddenObj'] should work *IF* the script fragment
      comes physically after the form element on the page.

      -rs-

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Accessing hidden objects in a form

        Ralph Snart wrote:[color=blue]
        > On 1 Jul 2004 17:03:44 -0700, Craig Anderson <craig.anderson @vykor.com> wrote:[/color]

        Please do not write attribution novels. The information you have
        included is already contained in the headers of the involved postings.
        Only the poster's name is required to see who wrote what of the quoted
        text. <http://www.netmeister. org/news/learn2quote.htm l>
        [color=blue]
        > [...]
        > document.forms['nameofform']['myHiddenObj'] should work *IF* the
        > script fragment comes physically after the form element on the page.[/color]

        When a DOM object becomes available depends on the DOM, on the UA.
        Furthermore, your referencing is neither standards compliant nor
        backwards compatible. The following is both:

        document.forms['nameofform'].elements['myHiddenObj']

        However, in most cases relative referencing, such as starting
        from the (parent) form element with `this' or `this.form' in
        an event handler, will suffice.


        PointedEars

        Comment

        • Dr John Stockton

          #5
          Re: Accessing hidden objects in a form

          JRS: In article <40EF3893.80103 06@PointedEars. de>, seen in
          news:comp.lang. javascript, Thomas 'PointedEars' Lahn
          <PointedEars@nu rfuerspam.de> posted at Sat, 10 Jul 2004 02:30:11 :[color=blue]
          >Ralph Snart wrote:[color=green]
          >> On 1 Jul 2004 17:03:44 -0700, Craig Anderson <craig.anderson @vykor.com>[/color]
          >wrote:
          >
          >Please do not write attribution novels. The information you have
          >included is already contained in the headers of the involved postings.
          >Only the poster's name is required to see who wrote what of the quoted
          >text. <http://www.netmeister. org/news/learn2quote.htm l>[/color]


          The current Internet draft REQUIRES more than that, and is quite
          encouraging to those who wish to provide more than is strictly called
          for.
          Read more about the Internet Engineering Task Force (IETF), the premier standards development organization (SDO) for the Internet.


          Please stop trying to be a petty dictator; Mussolini at least did (or so
          I have heard) something towards getting the trains to run on time, and
          dictatorial mis-rule is nowadays considered passé.



          Aside : ISTM that the "stringy" LZ is a little slower than the numeric
          one; unless others find otherwise, it's probably best used only
          for bases other than 10.



          TL wrote elsewhere :[color=blue]
          >The word "I" is always capitalized in English.[/color]

          Unfamiliar with e e cummings, then?

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
          Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
          Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
          No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

          Comment

          • Grant Wagner

            #6
            Re: Accessing hidden objects in a form

            Dr John Stockton wrote:
            [color=blue]
            > JRS: In article <40EF3893.80103 06@PointedEars. de>, seen in
            > news:comp.lang. javascript, Thomas 'PointedEars' Lahn
            > <PointedEars@nu rfuerspam.de> posted at Sat, 10 Jul 2004 02:30:11 :[color=green]
            > >Ralph Snart wrote:[color=darkred]
            > >> On 1 Jul 2004 17:03:44 -0700, Craig Anderson <craig.anderson @vykor.com>[/color]
            > >wrote:
            > >
            > >Please do not write attribution novels. The information you have
            > >included is already contained in the headers of the involved postings.
            > >Only the poster's name is required to see who wrote what of the quoted
            > >text. <http://www.netmeister. org/news/learn2quote.htm l>[/color]
            >
            > The current Internet draft REQUIRES more than that, and is quite
            > encouraging to those who wish to provide more than is strictly called
            > for.
            > http://www.ietf.org/internet-drafts/...-useage-00.txt
            >
            > Please stop trying to be a petty dictator; Mussolini at least did (or so
            > I have heard) something towards getting the trains to run on time, and
            > dictatorial mis-rule is nowadays considered passé.[/color]

            What I find most annoying is that he claims such "attributio n novels" waste
            bandwidth and make it harder to follow the flow of the usenet post, but Thomas'
            responses to such "novels" are longer (thereby wasting _more_ bandwidth) and
            disrupt the flow of the post even further.

            Much like banner ads on Web sites, I mentally "tune out" the noise introduced by
            quoted material on usenet, but his responses to the noise appear at first to
            contain meaningful information. It is only after I have read most of his response
            that I realize it is nothing more then additional noise.

            --
            Grant Wagner <gwagner@agrico reunited.com>
            comp.lang.javas cript FAQ - http://jibbering.com/faq


            Comment

            Working...