JS problem faced when field name has a dot

B

Blue

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>
 
L

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


--
 
H

Hal Rosser

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

hopethishelps
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top