Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

running coldfusion code

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
acampoma
Asked:
acampoma
  • 3
  • 2
1 Solution
 
dlewis9Commented:
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
 
acampomaAuthor Commented:
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
 
dlewis9Commented:
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
 
dlewis9Commented:
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
 
acampomaAuthor Commented:
Thank You very much!!!
You have been very helpful.
Alex Campomanes
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now