Solved

Button Event Handling with CF?

Posted on 2004-04-25
9
257 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

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

11 Experts available now in Live!

Get 1:1 Help Now