By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

JS problem faced when field name has a dot

P: n/a
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>
Oct 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lee
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
--

Oct 11 '06 #2

P: n/a
Blue wrote:
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 + ' ';
http://www.javascripttoolbox.com/bes...#squarebracket

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 11 '06 #3

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

hopethishelps
Oct 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.