Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax forrunning query from button

Status
Not open for further replies.

crimmelcp

Programmer
Oct 13, 2004
31
0
0
US
What is the correct syntax for running a query from a button?

Charlie Crimmel

Code:
<cfinput type="button" name="ShowAll" value="Show All" onclick="query="get_corporate">" width="175">
 
Hi Crimmelcp, this is Guba.

What you're triyng to do is not correct.
You start from the wrong point that you're dealing with a stand-alone application, running onto your PC.
This isn't true.
Your template isn't executed onto your pc but on the server.
So you must advise in some way the server that you want it to perform a query on the connected database and do something with the data it will retrieve.

You do this by sending some data to the server with a form post, a http url link or something.
If you want to do it via a form button use a submit button and set the action of the form to a template which executes the query.
This may be the same template itself.
Put this on the top of the template itself:

<CFIF IsDefined("FORM.ShowAll")>
<CFQUERY NAME... >
SELECT .....
</CFQUERY>
</CFIF>

Put ACTION=".....cfm" [the name of your template] in the form, practically a template that calls itself.

Modify your button as follows:

<cfinput type="Submit" name="ShowAll" value="Show All" width="175">

Then populate your template with data if they are available.

Hope this helps

Guba
 
Well, there is another way. Pretty much follows GubaGuba's methodlogy. If you still want to use the button to execute the query do this:

1) <input type="button" name="clickme" value="click me" onClick="process.cfm">

2) create a 'process.cfm' and have your query there and then use <cflocation url="output.cfm"> to output the result onto the screen.

The reason you use <cflocation url=""> to output the data is so if the user refreshes the page the query doesn't process again.

[sub]
____________________________________
Just Imagine.
[sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top