document.forms[0] and Struts (tags)

Discussion in 'Java' started by Jan-Friedrich Mutter, Jun 27, 2003.

  1. 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(myvalue) {
    //works
    document.forms[0].testProperty.value = myvalue;
    alert('document.forms[0].testProperty.value='+document.forms[0].testProperty.value);
    //doesn't work
    //(javascript error:
    //document.forms[0].dotted.prop is null or not an object)
    document.forms[0].dotted.prop.value = myvalue;
    alert('document.forms[0].dotted.prop.value='+document.forms[0].testProperty.value);
    }
    //-->

    <form>
    <input type="hidden" name="testProperty" value="">
    <input type="hidden" name="dotted.prop" value="">
    </form>

    Any comments are appreciated.

    Cheers,
    Jan.
     
    Jan-Friedrich Mutter, Jun 27, 2003
    #1
    1. Advertising

  2. (Jan-Friedrich Mutter) writes:

    > 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".


    It is illegal HTML, so you should check again whether it is *really*
    necessary.

    > document.forms[0].dotted.prop.value = myvalue;


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

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jun 27, 2003
    #2
    1. Advertising

  3. (Jan-Friedrich Mutter) writes:

    > document.forms[0].dotted.prop.value = myvalue;
    > alert('document.forms[0].dotted.prop.value='+document.forms[0].testProperty.value);


    Use getElementById('dotted.prop')
     
    Tor Iver Wilhelmsen, Jun 27, 2003
    #3
  4. "Tor Iver Wilhelmsen" <> wrote in
    message news:...
    <snip>
    > Use getElementById('dotted.prop')


    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.
     
    Richard Cornford, Jun 27, 2003
    #4
  5. Jan-Friedrich Mutter

    Chris Smith Guest

    Jan-Friedrich Mutter wrote:
    > 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".


    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.

    > I'm using IE 6. This is my code:
    >
    > <!--
    > function changeValue(myvalue) {
    > //works
    > document.forms[0].testProperty.value = myvalue;
    > alert('document.forms[0].testProperty.value='+document.forms[0].testProperty.value);
    > //doesn't work
    > //(javascript error:
    > //document.forms[0].dotted.prop is null or not an object)
    > document.forms[0].dotted.prop.value = myvalue;
    > alert('document.forms[0].dotted.prop.value='+document.forms[0].testProperty.value);
    > }
    > //-->


    Try:

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

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jun 28, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A. Brinkmann
    Replies:
    2
    Views:
    1,077
    A. Brinkmann
    Apr 16, 2004
  2. Greg Smith
    Replies:
    35
    Views:
    3,183
    Alex Kay
    Oct 24, 2004
  3. John M
    Replies:
    1
    Views:
    749
  4. Eric
    Replies:
    2
    Views:
    544
  5. Jan-Friedrich Mutter

    document.forms[0] and Struts (tags)

    Jan-Friedrich Mutter, Jun 27, 2003, in forum: Javascript
    Replies:
    4
    Views:
    440
    Chris Smith
    Jun 28, 2003
Loading...

Share This Page