Submit Your Article
Home Articles News Tutorials Videos Add An Article
Topics: Design Photoshop Programming PHP CSS Java Database Web Development Javascript Ajax
– Close + Open

Find Out More About DevWebPro!

Sign up for the newsletter


» Terms & Conditions

Welcome to the New DevWebPro!

DevWebPro Includes:
  Hundreds Of Tutorials   Developer News
  Unique Gadget Videos   Tons of Topics to Discuss
  Expert Advice   We Will Publish Your Articles

Using ColdFusion.navigate Instead Of Bindings

By: Raymond Camden
Friday, October 5th, 2007
Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook

A user pinged me during MAX (what’s wrong with you guys, didn’t I warn you about questions??!? ;) with a problem.

He wanted to use a CFDIV tag that bound to a form. The problem was – he didn’t want to actually do anything until the form was complete. He was using bindings, and everytime the form changed, the div reloaded, even though the form wasn’t complete. There are two simple solutions to this.

First off – one simple solution is to build the source file, and by source file I mean what your CFDIV is pointing to – build it such that it recognizes an incomplete form and simply doesn’t do anything. So consider this form:

<form id="myform">

Name <input type="text" id="name" name="name"><br>

Age <input type="text" id="age" name="age"><br>

</form>

You could simply check to see if name and age have values before you output a response. But that doesn’t technically answer his question. He wants the CFIDV to do nothing at all until the form is done.

So the second option is to just use a submit handler or a button to run a JavaScript function. This function can check the form – and when happy, use ColdFusion.navigate, or ColdFusion.Ajax.submitForm. I tend to prefer navigate, so here is an example.

<script>

function checkForm() {

   var name = document.getElementById("name").value;

   var age = document.getElementById("age").value;

   //Employ Mr. T error handling if(name == '') { alert('Enter a name, fool!'); return false; }

   if(age == '') { alert('I pity the fool who doesn't have an age!'); return false; }

   ColdFusion.navigate('div.cfm?name='+escape(name)+'&age='+escape(age),'resultdiv');

   return false;

}

</script>

<form id="myform">

Name <input type="text" id="name" name="name"><br>

Age <input type="text" id="age" name="age"><br>

<input type="button" value="Test" onClick="checkForm()">

</form>

<cfdiv id="resultdiv" style="background-color:##fff271" />

Topics: ,

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.
DevWebPro is an iEntry Network ® publication - © 1998-2010 All Rights Reserved