On 11/14/06, Jason T. Slack <[EMAIL PROTECTED]> wrote:
> I am on Day 5 with CF and Coming along nicely.
>
> I have a question on mixing CF and Javascript.
>
> Say I have the following with an onBlur event:
>
> <input type="textfield" name="upc" id="upc" size="12" maxlength="12"
> onblur="lookUpUPC(this.value);" />
>
> Here is the JS for LookUpUPC()
>
> function lookUpUPC(upc)
> {
> <cfquery name="ckUPC" datasource="#application.dsn#">
> SELECT Description, UnitPrice FROM Inventoryitems
> WHERE upc = <Cfqueryparam cfsqltype="cf_sql_varchar"
> value=upc>;
> </cfquery>
>
> <cfif ckUPC.recordCount EQ 1>
> alert("UPC FOUND");
> <cfelse>
> alert("UPC NOT FOUND");
> </cfif>
> }
>
>
> When LookUpUPC fires I get just the alert boxes that I coded in for
> information purposes. I tried hard coding the query with a valid upc
> in the database and still I get UPC not found.
>
> So I must be doing something wrong but I am not sure what.
>
> Can anybody shed some light?
In my opinion, this is one of the hardest things for new CFers to
understand. The key here is that the ColdFusion code is rendered
server-side and the javascript is executed client-side. For you, this
means that you can't do what you're trying to do the way you're trying
to do it. You're trying to execute server code in a client function.
You can accomplish the mission using AJaX, but not through inline
methods like these.
HTH.
Rob Wilkerson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:260373
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4