document.forms[0] and Struts (tags)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan-Friedrich Mutter

    #1

    document.forms[0] and Struts (tags)

    Hi,

    I have a problem to access a hidden field by javascript. The name of
    the field has a dot in it. That's the problem. But I need that dot
    because it is a "Stuts Property".
    I'm using IE 6. This is my code:

    <!--
    function changeValue(myv alue) {
    //works
    document.forms[0].testProperty.v alue = myvalue;
    alert('document .forms[0].testProperty.v alue='+document .forms[0].testProperty.v alue);
    //doesn't work
    //(javascript error:
    //document.forms[0].dotted.prop is null or not an object)
    document.forms[0].dotted.prop.va lue = myvalue;
    alert('document .forms[0].dotted.prop.va lue='+document. forms[0].testProperty.v alue);
    }
    //-->

    <form>
    <input type="hidden" name="testPrope rty" value="">
    <input type="hidden" name="dotted.pr op" value="">
    </form>

    Any comments are appreciated.

    Cheers,
    Jan.
  • Tor Iver Wilhelmsen

    #2
    Re: document.forms[0] and Struts (tags)

    jmutter@bigfoot .de (Jan-Friedrich Mutter) writes:
    [color=blue]
    > document.forms[0].dotted.prop.va lue = myvalue;
    > alert('document .forms[0].dotted.prop.va lue='+document. forms[0].testProperty.v alue);[/color]

    Use getElementById( 'dotted.prop')

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: document.forms[0] and Struts (tags)

      jmutter@bigfoot .de (Jan-Friedrich Mutter) writes:
      [color=blue]
      > I have a problem to access a hidden field by javascript. The name of
      > the field has a dot in it. That's the problem. But I need that dot
      > because it is a "Stuts Property".[/color]

      It is illegal HTML, so you should check again whether it is *really*
      necessary.
      [color=blue]
      > document.forms[0].dotted.prop.va lue = myvalue;[/color]

      How to access properties with illegal names:
      <URL:http://jibbering.com/faq/#FAQ4_25>
      I.e.,
      document.forms[0].elements["dotted.pro p"].value

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Richard Cornford

        #4
        Re: document.forms[0] and Struts (tags)

        "Tor Iver Wilhelmsen" <tor.iver.wilhe lmsen@broadpark .no> wrote in
        message news:ullvnz215. fsf@broadpark.n o...
        <snip>[color=blue]
        > Use getElementById( 'dotted.prop')[/color]

        Do not use getElementById to access form elements with JavaScript. Use
        the W3C HTML DOM level 2 specified document.forms collection to access
        the form and access the element as either a named or indexed property of
        either the form or the form's elements collection:-

        document.forms[nameOrIndex].elements[nameOrIndex];

        - complies with the latest W3C specification and is back-compatible with
        _every_ JavaScript capable browser currently in use.

        Richard.


        Comment

        • Chris Smith

          #5
          Re: document.forms[0] and Struts (tags)

          Jan-Friedrich Mutter wrote:[color=blue]
          > I have a problem to access a hidden field by javascript. The name of
          > the field has a dot in it. That's the problem. But I need that dot
          > because it is a "Stuts Property".[/color]

          In general, it's best not to post JavaScript questions to
          comp.lang.java. * groups. Java and JavaScript are not the same.
          Followups are set.
          [color=blue]
          > I'm using IE 6. This is my code:
          >
          > <!--
          > function changeValue(myv alue) {
          > //works
          > document.forms[0].testProperty.v alue = myvalue;
          > alert('document .forms[0].testProperty.v alue='+document .forms[0].testProperty.v alue);
          > //doesn't work
          > //(javascript error:
          > //document.forms[0].dotted.prop is null or not an object)
          > document.forms[0].dotted.prop.va lue = myvalue;
          > alert('document .forms[0].dotted.prop.va lue='+document. forms[0].testProperty.v alue);
          > }
          > //-->[/color]

          Try:

          (document.forms[0])["dotted.pro p"].value = myvalue;

          --

          The Easiest Way to Train Anyone... Anywhere.

          Chris Smith - Lead Software Developer/Technical Trainer
          MindIQ Corporation

          Comment

          Working...