ColdFusion 8: Getting the value of AJAX-ified controls

This post is more than 2 years old.

I ran into a problem last night trying to use JavaScript to read the value of a rich text field. I had assumed I could use the normal syntax I'd use for a form field:




But neither of these worked correctly. Turns out the JavaScript API provided in ColdFusion 8 has an API for this: ColdFusion.getElementValue(elementId, formID, attributeName). The formID and attributeName values are optional. Here is a simple example:

<script> function test() { var body = ColdFusion.getElementValue('body'); alert(body); return false; } </script>

<cfform onSubmit="return test()"> <cftextarea richtext="true" name="body" /> <input type="submit"> </cfform>

In case you are curious - the value includes all the HTML from the rich text value as you would probably expect.

The API can also be used on grids and trees. For grids, you have to provide the column name, and for trees you ask for either the node or the path value.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless 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