Skip to main content
Known Participant
September 27, 2006
Question

Problem with CF code in JavaScript

  • September 27, 2006
  • 1 reply
  • 272 views
Hi,

I am using <cfquery> tag in my javascript code , but I am getting a syntax error , because I am not able to assign the javascript value in my SQL where clause. Can you please correct my following code (particularly where condition)

Here is my function

function test () {
var licHolderState = "<cfoutput>#state#</cfoutput>";
with (document.testFrm) {

if (licHolder.value == '')
{
alert("You must enter a licHolder.");
licHolder.focus()
return false;
}

else if (licHolderState == 'XX')
var licHolderName = trim(licHolder.value);

<cfquery name = "licDetails" datasource = "Aftershock">
select * from licenceTbl where
name = ????? (should be licHolderName value)
</cfquery>

<cfif licDetails.Status EQ 0>

{
alert("Not a valid entry.");
licHolder.focus()
return false;
}
</cfif>

else
return true;
}
}

Thanks
This topic has been closed for replies.

1 reply

Participating Frequently
September 27, 2006
well, the Coldfusion code runs on the server, and generates the HTML page (that contains javascript in your case) to send to the browser. You can't do what you're trying to do directly.

There are 2 workarounds:
1) put all results from a "select status, licholdername from licensetbl" into a javascript array, thereby putting everything necessary to do that check in the javascript code itself
2) have your javascript function do an xmlhttprequest to the server a'la AJAX