Solved

running coldfusion code

Posted on 2000-03-14
5
347 Views
Last Modified: 2013-12-24
I am new to coldfusion and html althouth I am learning fast and getting by.
 Can anybody tell me how to run a section of cold fusion code on the ONCLICK event of a button and then go to an href location. Do I have to run code in another template or can I embed the code in a function or procedure within the same template??

For Example, I have a grid with data from a table with contains bacthes of transactions. My grid displays Batchid, Open date, close date, status, etc...
Under my grid, I have 3 buttons View batch, Delete batch, Close batch.
When My viewbatch button is clicked, I want to go to another page which will display the batch contents using the batchid of the selected batch(that was simple). But my problem is for the other two buttons. For the delete, I want to send a delete sql statement to the table for the selected batch and refresh(point back to) same page. For close, I want to send an update query to the table for the selected batch and return to the same page.

I am an experieced vb programmer and I think this is what's causing all of my problems.
Should I think of redesigning the process (layout of GUI) or is this an okay  way of doing it??
Is this a javascipt thing or can it be done using coldfusion tags alone??
I would really appreciate any feedback.
Thanks,
Alex Campomanes
0
Comment
Question by:acampoma
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
dlewis9 earned 100 total points
ID: 2620595
I'm not aware of any way to run Cold Fusion code after a page has been loaded like you can do with Javascript.  Cold Fusion obviously runs on the server while Javascript runs locally.  However, like you suggested, you can put it in a seperate template.  You then would go to that location within the ONCLICK event for your button, run your code, and then use whatever (CFLOCATION perhaps) to get back to the original page.  The code would run behind the scenes and it would look like just a simple page refresh when the button is clicked, as long as your SQL statement runs quickly.

I don't think there's anything wrong with the way you are doing it..I've done several things in the same manner, but with just using hyperlinks instead of buttons, so no Javascript is required.  Web programming is a different animal and you just have to change the thought process sometimes..
0
 
LVL 6

Author Comment

by:acampoma
ID: 2624478
I'll accept it but it would be helpfull if you could tell me how to obtain the value selected in the grid and pass it on to the next form as a parameter.
Thanks,
Alex
0
 
LVL 2

Expert Comment

by:dlewis9
ID: 2630545
My experience with CFGRID is that you make all your changes up front (edits, insert rows, delete rows) and then you submit the whole thing and Cold Fusion makes the appropriate changes to the database.  (You can add the insert and delete buttons to the bottom of the GRID through CFGRID's attributes).  I'm not sure that you can find out what row is selected, but I'll see what I can find out.  If you turn on debugging and submit the grid through a cfform, you can see all of the FORM variables..that may help.

I use the grid a little bit, but have resorted back to HTML tables in some cases.  From there, I just use hyperlinks to my processing page and pass a URL variable of the ID of the record that was clicked on (this would be the row that was selected if using a grid)..
0
 
LVL 2

Expert Comment

by:dlewis9
ID: 2635386
Checked around a little more and don't see a way to determine the selected row after you post the grid..

However, you can make one (or more) of the columns in the grid a hyperlink with a key value and it will take you to another page and will append the key value to the URL for your use.  In this manner, you could click on a batch value in the grid and it would take you to the "view" page for that batch, and from there, have two buttons for close and delete.  Those functions would be easy at that point since you know which record to work with.

Here's a modified example of something I'm using..this grid has two columns, 1 non-displayed key column, and one other column that uses the key column in the HREFKEY attribute of the CFGRIDCOLUMN.

<CFGRID NAME="outputgrid" HEIGHT="500" WIDTH="625" QUERY="qry_getloadinfo" INSERT="No" DELETE="No" SORT="Yes" BOLD="No" ITALIC="No" APPENDKEY="Yes" HIGHLIGHTHREF="Yes" GRIDDATAALIGN="LEFT" GRIDLINES="Yes" ROWHEADERS="No" ROWHEADERALIGN="LEFT" ROWHEADERITALIC="No" ROWHEADERBOLD="No" COLHEADERS="Yes" COLHEADERALIGN="LEFT" COLHEADERITALIC="No" COLHEADERBOLD="No" SELECTMODE="SINGLE" PICTUREBAR="No">
      <CFGRIDCOLUMN NAME="identity_key" HEADER="Key" HEADERALIGN="LEFT" DATAALIGN="LEFT" BOLD="No" ITALIC="No" SELECT="No" DISPLAY="No" HEADERBOLD="No" HEADERITALIC="No">
      <CFGRIDCOLUMN NAME="is_identifier" HEADER="IS Identifier" HEADERALIGN="LEFT" DATAALIGN="LEFT" BOLD="No" ITALIC="No" HREF="../../secure/is/akey/editentry.cfm" HREFKEY="identity_key" SELECT="Yes" DISPLAY="Yes" HEADERBOLD="No" HEADERITALIC="No">
</CFGRID>

when a row is clicked, it takes you to the specified address with a URL parameter called CFGRIDKEY attached (such as ../../secure/is/akey/editentry.cfm?CFGRIDKEY=149)

Hope that helps?!
0
 
LVL 6

Author Comment

by:acampoma
ID: 2641827
Thank You very much!!!
You have been very helpful.
Alex Campomanes
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now