?
Solved

Button Event Handling with CF?

Posted on 2004-04-25
9
Medium Priority
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 750 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

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

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…
What You Need to Know when Searching for a Webhost Provider
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 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