Question
Invalid CFML construct found on line inside <script> tag
Please find the below sample code,
<cfif local.fields[myName].readOnly>
<cfset thisAction = "view">
<cfelse>
<cfset thisAction = arguments.action>
</cfif>
<cfoutput>
<cfswitch expression="#thisAction#">
<cfcase value="edit">
<textarea id="#myName#"
name="#myName#"
rows="#local.fields[myName].rows#"
cols="#local.fields[myName].cols#"
onkeydown="maxlength#myName#(this,'#local.fields[myName].MaxLength#');maxlength1#myName#(this);"
onkeyup="maxlength#myName#(this,'#local.fields[myName].MaxLength#');maxlength1#FmyName#(this);"
>#IIF(len(local.fields[myName].value), DE(URLDecode(local.fields[myName].value)), DE(local.fields[myName].DefaultValue))#</textarea>
</cfcase>
<cfdefaultcase>
<cfif LEN(local.fields[myName].value)>
<pre>#IIF(len(local.fields[myName].value), DE(URLDecode(local.fields[myName].value)), DE(local.fields[myName].DefaultValue))#</pre>
<cfelse>
<!--- nothing to display yet --->
<span style="font-style: italic;">N/A</span>
</cfif>
</cfdefaultcase>
</cfswitch>
<script type="text/javascript">
function maxlength#myName#(textarea,maxLength){
var mainString = textarea.value;
var len = mainString.length;
if (len >= maxLength) {
textarea.value = textarea.value.substr(0, maxLength);
return false;
}
}//end maxlength
function maxlength1#myName#(textarea){
str = textarea.value;
newStr = str.replace(/[&#]/g, "" ); // error 'Invalid CFML construct found on line' , occurs here
if(isNaN(newStr)){
newStr = "";
} else{
}
textarea.value = newStr;
}//end maxlength
</script>
</cfoutput>
My goal is : I should not be able to enter special characters '#' and '&' in the textarea. I thought the following piece of code would stop me from entering # and & in the text area :
newStr = str.replace(/[&#]/g, "" );
However I'm getting error ,
Invalid CFML construct found on line newStr = str.replace(/[&#]/g, "" );
Please help me.
Thanks,
Vishnu
