Saturday, December 11, 2004

ColdFusion Programming -cfquery with javascript

Sample of using CFQUERY with javascript. The code allows the creation of an array of the CFQUERY. This array can then be manupulated by other javascript functions for searching a value in the array. Example of its use is doing a search for existing user name, if user enter a name that already exists, it will not post the submission. This will cut down the number of postings between server and client.

The following is the code sample.

<CFQUERY datasource = loanersrc" name = "loan">
select ID,MODEL_NO,SERIAL_NO,DESCRIPT from loanerwhere status = 'Available' ) ORDER BY MODEL_NO,SERIAL_NO
</cfquery><script language="javascript">
<cfset EQcount = 1>
myarray = new Array()
<cfloop query="loan">
myarray[#EQcount#]= new Array()
myarray[#EQcount#][1] = "#ID#"
myarray[#EQcount#][2] = "#REPLACE(ucase(MODEL_NO),CHR(34),"","ALL")#"
myarray[#EQcount#][3] = "#ucase(SERIAL_NO)#"
<cfset EQcount = EQcount + 1>
</cfloop>