Get Your Site Submitted for Free in the World's Largest B2B Directory!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

TheDevWeb
FlashNewz
DevWebPro





Getting The Value Of AJAX-ified Controls

By Raymond Camden
Expert Author
Article Date: 2007-06-20

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:

document.forms[0].body.value

or

document.getElementById('body')

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.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.




Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact

TheDevWeb is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal