Solved

Button Event Handling with CF?

Posted on 2004-04-25
9
260 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 10915549
Otherwise the closest you'll probably get is how anadkp showed you above.
0
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json_decode return null? 8 87
Interesting problem when moving between environments 6 45
cloud web Service looking for a home... 3 105
PHP in Apache server 20 92
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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