Skip to main content
Inspiring
February 2, 2009
Question

if statement

  • February 2, 2009
  • 2 replies
  • 339 views
I have this code like this:
<cfquery name=name datasource=datasource>
Select *
From table
</cfquery>
<script language="JavaScript">
if (condition)
{
}
</script>

my question is how can I compare a column from the database from a text in if statement in javascript?

thanks
This topic has been closed for replies.

2 replies

Inspiring
February 2, 2009
You can use the toscript tag to bring your query results into javascript. Details are in the cfml reference manual. If you don't have one, the internet does.

Inspiring
February 2, 2009
dchard wrote:
>
> my question is how can I compare a column from the database from a text in if
> statement in javascript?
>
> thanks
>

Most likely, by the simple phrasing of your question, you can *NOT* do
what you think you want to do.

An important beginning concept to to fully understand is the difference
between CFML that runs on the *server* and JavaScript that runs on the
*client* and never will the two meet. Before a user client ever sees an
opening <html...> or doctype tag, the CFML has completed its work and
moved on to an entirely new request for a completely different user.

You can use CFML to dynamically build JavaScript to be delivered to the
client. This is very powerful and is no different then using CFML to
generate HTML or text or anything else you would like to deliver to a
client.

You can use JavaScript to make requests to a server. These requests can
be for CFML templates that return new, dynamically generated information
to the client. When done asynchronously and XML is used to return the
information, this is popularly called AJAX. But that is not the only
way to do this.


Now if we had some hint of your goal, we could probably give you some
hints. But without that, I can only say, "Sorry ColdFusion and
JavaScript do not mix."

Ian