Solved

Button Event Handling with CF?

Posted on 2004-04-25
9
258 Views
Last Modified: 2013-12-24
I have an HTML button.  I want CF to handle it's onClick.  Is there any way to do this, other than through a JavaScript function?  

Someone told me that I could put the button in a form, and then the button would be of type="submit", then the form's action would be where I wanted the button to go, but I want to do a couple of other things first.  

I guess my real question is: does this have to be done with JavaScript, or can CF do any event handling? and, if so, how does it happen?
0
Comment
Question by:PrtyAnimll
9 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 10914314
Hi PrtyAnimll,

Depends on what you want to do.

<form name="test" method="post" action="testaction.cfm">
    <input type="submit" name="Submit" value="Submit">
</form>

When the submit button is pressed, all form fields are posted to testaction.cfm and from there you can do anything you like.

Regards
Plucka
0
 
LVL 17

Expert Comment

by:anandkp
ID: 10915247
If the form button is type="submit - then as soon as its clicked - it will submit the form to its action page ...

incase u wanna do some additional events on this [b4 submitting the form] ... u'll need to use javascript for thsi ...

<form name="frm" action="mypage.cfm">
<input type="button" name="x" onclick="alert('hi');document.frm.submit();return false">
</form>

hth

K'Rgds
Anand
0
 
LVL 20

Accepted Solution

by:
trailblazzyr55 earned 250 total points
ID: 10915539
Well to answer you question directly, no..

You need javascript to use any other buttons than type = "Submit", "Reset", or "Button"(normally used w/javascript) . You're pretty limited to those unless you start adding some javascript. Thing is it's not very hard to perform simple functions with javascript buttons.

Here's a simple link button...

In the head write this:  
<script language=javascript> function goTO() { window.location = "http://www.yourpage.com"; } </script>

And in the body:
<form>
<input type=button value="Your Button" onClick="goTO()">
</form>

But there isn't a way really for CF to handle the onClick(), it'd just be easier to use javascript.

Good luck!
Regards,
~trail
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 10915549
Otherwise the closest you'll probably get is how anadkp showed you above.
0
New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

 
LVL 17

Expert Comment

by:Tacobell777
ID: 10915853
You need to use Javascript to handle events, but the closed to what I think you want to try and do is the following
PSEUDO CODE
<form .............>

<input type="submit" name="btnCancel" value="Cancel"> <input type="submit" name="btnSubmit" value="Submit">
</form>

On the action page (receiving page)

<cfif isDefined("form.btnCancel")>
 do cancel stuff
</cfif>

<cfif isDefined("form.btnSubmit")>
 do submit stuff
</cfif>
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10919479
Just to clarify

Cold Fusion can NOT handle events.  The reason is that events happen client side.  SUch as onClick onChange OnBlur etc...

These are handled by Javascript.

Now in the above posts let me clarify the difference in what is being shown:

PLucka's response - this is just standard submit behavior of a form - it is not handling any events nor doing anything based on the submit - probably not what you are looking for

ananskp & trailblazzyr55 responses - these are using javascript to handle the onClick of a generic button - this could be what you are looking for, but means that you have to use javascript to submit the page - and the user may turn off javascript

TacoBell777's response - this is using the standard submit of the form, but shows how you could then have different submit buttons and have cold fusion process the form differently depending on which button was used to subit the form - but it is handled server side AFTER the form is submitted.

I would recommend using TacoBell's solution, but adding to it by also defining the onSubmit attribute in the form.  This way you can use javascript to do some client side validation BEFORE the form submits, but if javascript is disabled the form will still submit and you have the server side actions in additon.

Hope that helps.
0
 
LVL 15

Expert Comment

by:tim_cs
ID: 10928755
If you wanted to do some simple stuff like error checking you could use <cfinput> and add in attributes like maxLength=200 OR validate="date"


http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Tags53.htm
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 10962771
Hi PrtyAnimll,

Glad I was able to help, Cheers!

B'regards,
~trail
0
 

Author Comment

by:PrtyAnimll
ID: 10962785
ty for all the help everyone..  

mrichmon, you still get props, though you didnt get points!!

-ward
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

16 Experts available now in Live!

Get 1:1 Help Now