Accessing JS variables in CF?

2003-03-24 Thread Bosky, Dave
I have a form field called Zip and want to lookup/populate the city/state
fields 
based on the zipcode entered. I'm thinking of using an onblur event to call
the
following JS function. Question how can I access the variable passed to the
JS
function inside a CF query? Is there a better way of accomplishing this
lookup?

CFPARAM name=vZip default=
CFINPUT TYPE=text NAME=Zip  SIZE=5 MAXLENGTH=5
onBlur=zipLookup(this.form.Zip)

script language=JavaScript
function zipLookup(zipcode) {
if ((zipcode == ) || (zipcode.length  5) || (zipcode.length  5)) {
alert('Please enter a five digit zipcode!');
document.Log.zip.value = '';
document.Log.zip.focus();
return false;
}
else
/script
CFSET vZip = script language=JavaScriptzipcode/script

CFQUERY name=qZipLook datasource=dsn
SELECT City, State 
FROM tbl_zipcodes
WHERE zipcode = Trim(Variables.vZip) 
/CFQUERY
CFIF IsDefined(qZipLook.RecordCount) AND qZipLook.RecordCount EQ
1
AND Variables.vZip is not 
script language=JavaScript
document.Log.City.value =
'cfoutput#qZipLook.City#/cfoutput';
document.Log.State.value =
'cfoutput#qZipLook.State#/cfoutput';
/script
/CFIF
script language=JavaScript
return true;
}
/script

thanks,
Dave




HTC Disclaimer:  The information contained in this message may be privileged and 
confidential and protected from disclosure. If the reader of this message is not the 
intended recipient, or an employee or agent responsible for delivering this message to 
the intended recipient, you are hereby notified that any dissemination, distribution 
or copying of this communication is strictly prohibited.  If you have received this 
communication in error, please notify us immediately by replying to the message and 
deleting it from your computer.  Thank you.
~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4



RE: Accessing JS variables in CF?

2003-03-24 Thread Dan G. Switzer, II
Dave,

You can't inter-mingle server-side code (CF) and client-side code (JS.) CF
runs strictly on the server, while the JS in this example runs strictly on
the client-side.

You can use techniques like covered in my article Client-to-Server
Communication Using DHTML--which is at:

http://www.pengoworks.com/index.cfm?action=articles:gatewayApi

To simplify the work, I've written a Gateway JavaScript API (JSAPI) which
can be downloaded at:
http://www.pengoworks.com/workshop/js/gateway/

Conveniently enough, I even have included examples to do what you're trying
to do:
http://www.pengoworks.com/workshop/js/gateway/zipcode.htm

Hope this helps!

-Dan


 -Original Message-
 From: Bosky, Dave [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 24, 2003 10:00 AM
 To: CF-Talk
 Subject: Accessing JS variables in CF?
 
 I have a form field called Zip and want to lookup/populate the city/state
 fields
 based on the zipcode entered. I'm thinking of using an onblur event to
 call
 the
 following JS function. Question how can I access the variable passed to
 the
 JS
 function inside a CF query? Is there a better way of accomplishing this
 lookup?
 
 CFPARAM name=vZip default=
 CFINPUT TYPE=text NAME=Zip  SIZE=5 MAXLENGTH=5
 onBlur=zipLookup(this.form.Zip)
 
 script language=JavaScript
 function zipLookup(zipcode) {
 if ((zipcode == ) || (zipcode.length  5) || (zipcode.length  5)) {
   alert('Please enter a five digit zipcode!');
   document.Log.zip.value = '';
   document.Log.zip.focus();
   return false;
 }
 else
 /script
   CFSET vZip = script language=JavaScriptzipcode/script
 
   CFQUERY name=qZipLook datasource=dsn
   SELECT City, State
   FROM tbl_zipcodes
   WHERE zipcode = Trim(Variables.vZip)
   /CFQUERY
   CFIF IsDefined(qZipLook.RecordCount) AND qZipLook.RecordCount EQ
 1
   AND Variables.vZip is not 
   script language=JavaScript
   document.Log.City.value =
 'cfoutput#qZipLook.City#/cfoutput';
   document.Log.State.value =
 'cfoutput#qZipLook.State#/cfoutput';
   /script
   /CFIF
 script language=JavaScript
 return true;
 }
 /script
 
 thanks,
 Dave
 
 
 
 
 HTC Disclaimer:  The information contained in this message may be
 privileged and confidential and protected from disclosure. If the reader
 of this message is not the intended recipient, or an employee or agent
 responsible for delivering this message to the intended recipient, you are
 hereby notified that any dissemination, distribution or copying of this
 communication is strictly prohibited.  If you have received this
 communication in error, please notify us immediately by replying to the
 message and deleting it from your computer.  Thank you.
 
~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4