[SOLVED] Event Chain detection

This is a discussion on "[SOLVED] Event Chain detection" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Event Chain detection are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 17th, 2008, 21:33
New Member
Join Date: Aug 2007
Location: New York
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Event Chain detection

There is an onchange event handler attached to the INPUT element on the FORM. There are also two buttons Submit and Cancel that process form data.

I would like to detect if the onchange event handler for the form INPUT element occured as a result of user clicking on the Cancel button. In this case validation logic in the onchange event handler should not be activated.

Is there a way to detect this in JavaScript?

Thank you,
Stan.
Reply With Quote

  #2 (permalink)  
Old Jan 18th, 2008, 04:04
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Event Chain detection

I didn't think the reset button triggered the onchange event but if it does, it would be easy to avoid...

Just set a global variable.. and then set it to true when the cancel button is clicked... In your onchange function, just add some logic to aviod going any further in the function...

Code: Select all
var cancelClicked = false;

// this is the onchange function for the input element

function onchangeInput()
{
     if (cancelClicked)
     {
         cancelClicked = false;
         return;
     }
      // rest of the logic here
}
Then your reset button just has to look like this

HTML: Select all
<input type="reset" value="cancel" onclick="cancelClicked = true;" />
Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Jan 18th, 2008, 14:13
New Member
Join Date: Aug 2007
Location: New York
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Event Chain detection

This is exactly the issue itself:
the onclick handler is called only after the onchage handler completes.

the flag will be set after onchange and have no use in this case.

Is there such thing as an event queue in JS? I am puzzeled how to solve this one.

Regards,
Stan.
Reply With Quote
  #4 (permalink)  
Old Jan 18th, 2008, 18:17
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Event Chain detection

Instead of using onclick for the cancel button use onmousedown instead. Then when the mouse button is pressed down the variable is set. The actual reset functionality won't happen until a full click is completed
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Jan 18th, 2008, 18:33
New Member
Join Date: Aug 2007
Location: New York
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Event Chain detection

Rakuli, Great idea!

Really solves a lot of my application design problems.

The sequence of events noted:
onmousedown
onchange
onclick

Thank you,
Stan.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Stop Propagation event after onchange Select!!!! abdoukadri JavaScript Forum 8 Dec 5th, 2007 20:50
[SOLVED] Os Detection simonb PHP Forum 16 Nov 26th, 2007 23:59
Chain Email Surveys... Grrr! Rakuli Webforumz Cafe 6 Oct 18th, 2007 17:50
ie mac detection jimz JavaScript Forum 2 Jul 27th, 2006 22:07
EVENT: SPARK - Flash Event Flasher Flash & Multimedia Forum 0 Nov 15th, 2005 10:08


All times are GMT. The time now is 01:22.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43