Solved

Button Event Handling with CF?

Posted on 2004-04-25
9
261 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why addon domain redirects to the original domain? 8 73
DNS, website, godaddy 6 90
Domino Website - Redirection 12 84
Best practices for sharing large amounts of data 9 99
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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