Bug with JavaScript bind and textareas
I was playing around with a little something today when I ran across a bug. If you try to use cfajaxproxy and bind a textarea to a JavaScript function, you will get an error if the textarea contains a newline. Consider:
<cfajaxproxy bind="javascript:setCount({body2@keyup})">
<script>
function setCount(r) {
var cdiv = document.getElementById('counter');
cdiv.innerHTML = cdiv.innerHTML + 'you did it' + r + '<br>';
}
</script>
<cfform name="ray">
<cftextarea id="body2" name="body2"></cftextarea>
</cfform>
<div id="counter"></div>
Turns out the newline breaks the JavaScript call. If you switch to a CFC call it works fine, but for what I was doing, I didn't need to call the server. Todd pointed out that this is rather trivial code, I could have just done this:
<cftextarea id="body2" name="body2" onkeyup="javascript:setCount(this.value);"></cftextarea>
But I wanted to keep it inside cfajaxproxy. I'll report a bug on this in a few minutes.
Comments
The newline bug which you have reported has already been fixed. But it is just that it could not make it into the first hot fix.
<cfif IsDefined("form.user_comment")>
<cfset request.textarea_field_value = form.user_comment>
<cfelse>
<cfset request.textarea_field_value = "">
</cfif>
<cfif IsDefined("url.call_cfajaxproxy")>
<cfset request.call_cfajaxproxy = url.call_cfajaxproxy>
<cfelse>
<cfif IsDefined("form.call_cfajaxproxy")>
<cfset request.call_cfajaxproxy = form.call_cfajaxproxy>
<cfelse>
<cfset request.call_cfajaxproxy = "N">
</cfif>
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...;
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT LANGUAGE="JavaScript2.0" TYPE="text/javascript">
function jsf_test() {var jsv_just_testing = 1;}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CFAJAXPROXY BUG</title>
</head>
<body>
This was tested with an Internet Explorer 7 browser on WinXP and shows that CFAJAXPROXY has a bug in it related to new lines in textarea
fields. You can make the "Unterminated string constant" error occur by donig the following:
<ol>
<li>Enter "1" followed by the Enter key to created a newline</li>
<li>Enter "2" on the new line</li>
<li>Click the Submit button</li>
<li>
<cfif request.call_cfajaxproxy EQ "Y">
Still think this is not a problem with CFAJAXPROXY?
<a href="test.cfm?call_cfajaxproxy=N">Click here</a> to try <strong>without</strong> the call to cfajaxproxy.
<cfelse>
<a href="test.cfm?call_cfajaxproxy=Y">Click here</a> to try <strong>with</strong> the call to cfajaxproxy.
</cfif>
</li>
</ol>
<cfif IsDefined("form.user_comment")>
Values posted at <cfoutput>#TimeFormat(now(),"h:mm:ss tt")#</cfoutput>
</cfif>
<CFFORM ACTION="test.cfm" METHOD="POST" id="testit" name="test_form">
<TEXTAREA NAME="user_comment" COLS="50" ROWS="10"><cfoutput>#request.textarea_field_value#</cfoutput>
http://kb.adobe.com/selfservice/viewContent.do?ext...


vishy