JS problem faced when field name has a dot

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

    JS problem faced when field name has a dot

    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 "myfieldnam e" below is
    "message.bo dy". The dot in the field name is giving problem to the JS.

    The JS stop working if it is:
    document.myform name.message.bo dy.value += ' ' + theSmilie + ' ';
    document.myform name.message.bo dy.focus();

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

    =============== =============== =============== =
    <script language="javas cript">
    <!--

    function emoticon(theSmi lie) {
    document.myform name.myfieldnam e.value += ' ' + theSmilie + ' ';
    document.myform name.myfieldnam e.focus();
    }

    //-->
    </script>

    </head>
    <body>


    <form name="myformnam e">
    <textarea name="myfieldna me" cols="48" rows="10"></textarea>

    <a href="javascrip t:emoticon(':sm ile:')"><img src="gfx/icon_smile.gif" "
    border="0"></a>
    <br>
    <a href="javascrip t:emoticon(':gr in:')"><img src="gfx/icon_biggrin.gi f""
    border="0"></a>
  • Lee

    #2
    Re: JS problem faced when field name has a dot

    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 "myfieldnam e" below is
    >"message.body" . The dot in the field name is giving problem to the JS.
    >
    >The JS stop working if it is:
    >document.myfor mname.message.b ody.value += ' ' + theSmilie + ' ';
    >document.myfor mname.message.b ody.focus();
    >
    >How to go about this? I cannot change the field name.

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

    document.myform mame.elements["message.bo dy"].value ...




    --

    Comment

    • Matt Kruse

      #3
      Re: JS problem faced when field name has a dot

      Blue wrote:
      But my problem is, in my PHP script, the "myfieldnam e" below is
      "message.bo dy". The dot in the field name is giving problem to the JS.
      The JS stop working if it is:
      document.myform name.message.bo dy.value += ' ' + theSmilie + ' ';


      --
      Matt Kruse




      Comment

      • Hal Rosser

        #4
        Re: JS problem faced when field name has a dot

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

        hopethishelps


        Comment

        Working...