Bug with JavaScript bind and textareas

This post is more than 2 years old.

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.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by vishy posted on 9/11/2007 at 5:56 PM

cfajaxproxy has one more important bug in dealing with symbolic links. you are forced to put the cfc's in wwwroot folder if your default application is based on symbolic links. Adobe has recorded it as bug but and this will also be resolved soon.


Comment 2 by Rakshith posted on 10/7/2007 at 5:28 PM

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.

Comment 3 by Vincent Krist posted on 3/4/2008 at 1:19 AM

I just applied hotfix 2 and it does not mention a fix for the issue of newlines and cfajaxproxy. In addition, I am still experiencing the issue.

Comment 4 by Raymond Camden posted on 3/4/2008 at 1:21 AM

Be patient. I know for a fact this bug is logged with Adobe. I'm sure the next update will have the fix.

Comment 5 by Vincent Krist posted on 3/4/2008 at 2:16 AM

I suppose I should clarify a little more. I am including a fairly simple example of code from a file named test.cfm that shows the bug in CFAJAXPROXY:

<cfif IsDefined("form.user_comment")>
<cfset request.textarea_field_value = form.user_comment>
<cfset request.textarea_field_value = "">
<cfif IsDefined("url.call_cfajaxproxy")>
<cfset request.call_cfajaxproxy = url.call_cfajaxproxy>
<cfif IsDefined("form.call_cfajaxproxy")>
<cfset request.call_cfajaxproxy = form.call_cfajaxproxy>
<cfset request.call_cfajaxproxy = "N">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1...">
<html xmlns="http://www.w3.org/1999/xhtml">
<SCRIPT LANGUAGE="JavaScript2.0" TYPE="text/javascript">
function jsf_test() {var jsv_just_testing = 1;}

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CFAJAXPROXY BUG</title>

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:
<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>
<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.
<a href="test.cfm?call_cfajaxproxy=Y">Click here</a> to try <strong>with</strong> the call to cfajaxproxy.
<cfif IsDefined("form.user_comment")>
Values posted at <cfoutput>#TimeFormat(now(),"h:mm:ss tt")#</cfoutput>
<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>

Comment 6 by Raymond Camden posted on 3/4/2008 at 2:54 AM

Um - not sure why you need to clarify. It is _definitely_ a bug, and Adobe _definitely_ has it reported. :)

Comment 7 by Vincent Krist posted on 3/4/2008 at 2:58 AM

Sorry, I didn't see your reply before I clarified. Thanks for the information.

Comment 8 by Vincent Krist posted on 3/14/2008 at 8:34 AM

I just installed HOTFIX 3 and it is still a problem. There is also nothing in the HOTFIX 3 release notes that indicates it was fixed.


Comment 9 by Raymond Camden posted on 3/14/2008 at 6:40 PM

It will be. I know it's recorded. Don't forget Adobe is working on an update. Not a hotfix, but an update.