I have created a web form, but what I would like it to do (and I'm not sure if 
this is possible with Coldfusion?) is when a user enters their employee number 
into a text field without a page refresh it runs a database lookup and 
populates other fields in the form with that employees information (name, 
address etc)

Is this possible and is anybody willing to share any code snippets on how to do 
this.  

-----
I can't speak to using Ajax in CF7, but, as far as the concept of using Ajax, 
this works for me. There are other ways of doing it and using jquery and other 
CF tags - this is a simplified version.



<!--- file tmp.cfm --->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<!--- I never tried this in CF7, so this may be where some additional
                research and work is needed if this tag isn't available. --->
<cfajaximport>

<script type="text/javascript">
function fillData() {
        <!--- again, not sure about this in CF7. This is to illustrate the 
concept. --->
        ColdFusion.Ajax.submitForm('testform', 'tmp2.cfm', callbackFunc);       
        
}

function callbackFunc(somedata) {
        var x = somedata.split("|");
        document.getElementById('showdata1').value = x[0];
        document.getElementById('showdata2').value = x[1];
}

</script>

</head>

<body>

<form name="testform">
        Search for <input type="text" name="searchData" id="searchData" 
size="10" onclick="fillData()" /><br /><br />
        
        Emp ID <input type="text" name="showData1" id="showData1" size="10" 
/><br />
        Age <input type="text" name="showData2" id="showData2" size="2" />
        
        <!--- other stuff, like a submit button for submitting showData, etc. 
(if you
                        don't use Ajax for this part) --->
</form>


</body></html>
<!--- end file tmp.cfm --->

<!--- file tmp2.cfm --->

<!--- No head section, no body section, your application.cfm/application.cfc
                can't leave any info on the page (e.g., an HTML style remark) 
and you
                can't have anything in OnApplicationEnd.cfm that puts anything 
on the page --->

<cfparam name="FORM.seachData" default="">
<!--- Here you do a query lookup based on what was submitted in FORM.seachData.
                Let's say it returned employee ID and age. Instead of using 
query
                data I'm using cfset for illustration purposes to get a couple 
of
                variables. --->
<cfset eid = '23456789'>
<cfset eage = 20>

<!--- here's what Ajax sends back to your callback function --->
<cfoutput>#eid#|#eage#</cfoutput>

<!--- end file tmp2.cfm --->            

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342676
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to