Heya,
That ain't gonna work! Your Cold Fusion code gets compiled and
executed on the server before it gets sent to the browser, where the
Javascript executes... when Cold Fusion processes your template, the
value of 'y.ASSETNUMBER.value' doesn't exist yet.
The only way you could do something like this is to pass the
Javascript variable back to the server somehow. You can use a hidden
frame that refreshes and passes values around... it a bit fiddly but
it can be done... in the long run you're probably better checking for
dupes after the form is submitted, as if someone has Javascript turned
off, they might be able to get past your validation and put duplicates
in the database anyway.
bye!
Monday, March 1, 2004, 10:58:08 AM, you wrote:
GL> Hi,
GL> I'd like to search duplicates in the database before submit the form. The question
is how can I pass javascript variables to a SQL query. CF complaints (variable y is
not defined) if I use it
GL> directly:
GL> y = document.AddNewItem;
GL> // search existing items in whole database
GL> <CFQUERY NAME="qSearchDuplicates" DATASOURCE="#request.app.dsn#"
BLOCKFACTOR="100">
GL> SELECT HardwareAddr,IPAddr,SERIALNUMBER,ASSETNUMBER
GL> FROM tblPrinter_inventory
GL> WHERE
GL> <CFIF y.ASSETNUMBER.value IS NOT "">
GL> AND (tblPrinter_inventory.ASSETNUMBER = 'y.ASSETNUMBER.value')
GL> </CFIF>
GL> <CFIF y.HardwareAddr.value IS NOT "">
GL> AND (tblPrinter_inventory.HardwareAddr = 'y.HardwareAddr.value')
GL> </CFIF>
GL> <CFIF y.IPAddr.value IS NOT "">
GL> AND (tblPrinter_inventory.IPAddr = 'y.IPAddr.value')
GL> </CFIF>
GL> <CFIF y.SERIALNUMBER.value IS NOT "">
GL> AND (tblPrinter_inventory.SERIALNUMBER = 'y.SERIALNUMBER.value')
GL> </CFIF>
GL> </CFQUERY>
GL> if (qSearchDuplicates.recordcount == 0) {
GL> y.submit();
GL> }
GL> else {
GL> alert("Printer with the same either Hardware or IP Address, Serial or Asset
number already exists in the Inventory database.\n\nPlease check the details and try
again.");
GL> return false
GL> }
GL> Thanks,
GL> George
GL> AMES (Adult Multicultural Education Services)
GL> www.ames.net.au
GL> Disclaimer
GL> **********************************************************************
GL> This email and any attachments may be confidential.
GL> If received in error, please contact us and delete all copies.
GL> Before opening or using attachments you should check them for viruses
GL> or defects.
GL> Regardless of any loss, damage or consequence, whether caused by the
GL> negligence of the sender or not, resulting directly or indirectly from
GL> the use of any attached files our liability is limited to resupplying
GL> any affected attachments.
GL> Any representations or opinions expressed are those of the individual
GL> sender, and not necessarily those of Adult Multicultural Education
GL> Services (AMES).
GL> **********************************************************************
GL> ---
GL> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
GL> To unsubscribe send a blank email to [EMAIL PROTECTED]
GL> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
GL> http://www.mxdu.com/ + 24-25 February, 2004
-----------------------
Ryan Sabir
Newgency Pty Ltd
2a Broughton St
Paddington 2021
Sydney, Australia
Ph (02) 9331 2133
Fax (02) 9331 5199
Mobile: 0411 512 454
http://www.newgency.com/index.cfm?referer=rysig
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004