JS problem faced when field name has a dot

Discussion in 'Javascript' started by Blue, Oct 11, 2006.

  1. Blue

    Blue Guest

    The JS below will insert predefined text into the area text box when you
    click on the smileys. This sample script is working fine.

    But my problem is, in my PHP script, the "myfieldname" below is
    "message.body". The dot in the field name is giving problem to the JS.

    The JS stop working if it is:
    document.myformname.message.body.value += ' ' + theSmilie + ' ';
    document.myformname.message.body.focus();

    How to go about this? I cannot change the field name.

    ==============================================
    <script language="javascript">
    <!--

    function emoticon(theSmilie) {
    document.myformname.myfieldname.value += ' ' + theSmilie + ' ';
    document.myformname.myfieldname.focus();
    }

    //-->
    </script>

    </head>
    <body>


    <form name="myformname">
    <textarea name="myfieldname" cols="48" rows="10"></textarea>

    <a href="javascript:emoticon(':smile:')"><img src="gfx/icon_smile.gif""
    border="0"></a>
    <br>
    <a href="javascript:emoticon(':grin:')"><img src="gfx/icon_biggrin.gif""
    border="0"></a>
     
    Blue, Oct 11, 2006
    #1
    1. Advertising

  2. Blue

    Lee Guest

    Blue said:
    >
    >The JS below will insert predefined text into the area text box when you
    >click on the smileys. This sample script is working fine.
    >
    >But my problem is, in my PHP script, the "myfieldname" below is
    >"message.body". The dot in the field name is giving problem to the JS.
    >
    >The JS stop working if it is:
    >document.myformname.message.body.value += ' ' + theSmilie + ' ';
    >document.myformname.message.body.focus();
    >
    >How to go about this? I cannot change the field name.



    Next time, put a little thought into the field names.

    document.myformmame.elements["message.body"].value ...

    http://www.jibbering.com/faq/#FAQ4_25


    --
     
    Lee, Oct 11, 2006
    #2
    1. Advertising

  3. Blue

    Matt Kruse Guest

    Matt Kruse, Oct 11, 2006
    #3
  4. Blue

    Hal Rosser Guest

    you may have better luck accessing the form elements using index numbers:
    document.forms[0].elements[x].value

    hopethishelps
     
    Hal Rosser, Oct 11, 2006
    #4
    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.

Share This Page