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.

Like This?

If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can also subscribe to the email feed to get notified of new posts.