473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

jQuery .on() api and bypassing it

Frinavale
9,735 Expert Mod 8TB
I am still a novice when it comes to using jQuery and it has been a while since I've developed in the web.

I am taking advantage of something and wanted to make sure that what I am doing is correct.

I using the jQuery .on() api attach an event handler function for form.submit events within the document.


What I have discovered is that the the event handler is not executed if I directly access the form to submit it; however, if I use jQuery to create it's form object, the event handler is executed.

For example if I use:
Expand|Select|Wrap|Line Numbers
  1. <select id="SelectedMasterID" onchange="this.form.submit();" name="SelectedMasterID"> 
  2. <!-- options -->
  3. </select>
The above code will bypass the event handler method.

However, if I use the following it will not be bypassed:
Expand|Select|Wrap|Line Numbers
  1. <select id="SelectedMasterID" onchange="$(this).parents('form').submit();" name="SelectedMasterID"> 
  2. <!-- options -->
  3. </select>
This is actually beneficial to my situation because in some cases I want to bypass the method attached to the submit event.

According to the .on() api documentation:
The .on() method attaches event handlers to the currently selected set of elements in the jQuery object.
So, am I correct in thinking that this.form.submit() will always bypass the event handler?

Thanks,

-Frinny
Oct 23 '13 #1

✓ answered by Dormilich

So, am I correct in thinking that this.form.submit() will always bypass the event handler?
that’s like with apples and pears. the submit() in this.form.submit() is different from the submit() in $('form').submit() (which is actually a shortcut for trigger('submit')).

further details may depend on how exactly you defined the handler.

3 1934
Dormilich
8,658 Expert Mod 8TB
So, am I correct in thinking that this.form.submit() will always bypass the event handler?
that’s like with apples and pears. the submit() in this.form.submit() is different from the submit() in $('form').submit() (which is actually a shortcut for trigger('submit')).

further details may depend on how exactly you defined the handler.
Oct 23 '13 #2
Dormilich
8,658 Expert Mod 8TB
although, if you are using jQuery, why are you using event attributes? wouldn’t it be easier to use
Expand|Select|Wrap|Line Numbers
  1. $('#SelectedMasterID').on('change', function() {
  2.     this.form.submit();
  3.     // or
  4.     $(this.form).submit();
  5.     // or
  6.     if (validate(this)) {
  7.         this.form.submit();
  8.     }
  9. });
  10.  
?
Oct 23 '13 #3
Frinavale
9,735 Expert Mod 8TB
I wanted to handle every item that submits the form, not just that one <select>.

I ended up changing my design so that ajax calls are only made in particular cases.
Oct 24 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Corey Olsen | last post by:
Can anyone point me to some documentation on bypassing validation controls when a user selects cancel? What I have is a user control with a form to fill out information on a subject. The user...
0
by: shapper | last post by:
Hello, I want to use JQuery on my ASP.NET projects. Consider the first example on the following page: http://p.sohei.org/stuff/jquery/tablehover/demo/demo.html I am trying to create a...
26
by: RobG | last post by:
Do some of the regulars here need to re-think their (sometimes strident) opposition to libraries? Both Microsoft and Nokia have announced support for jQuery. It seems to have gained quite a bit...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
1
by: faultykid | last post by:
I would like to store a variable then call it back later. I have a variable on line 198 www = ''+this._ad.clickUrl+''; and on line 321 i try document.write(www);
0
by: amskape | last post by:
hi Friends, I need to Upload some files in a Listing , by clicking corresponding Upload link, then a popup window will come with Browse option as Shown in attachment File. My actual need is...
0
by: bala venkata siva ram kum | last post by:
Hi all, I am working with menu. for that i download(jquery code) in the net. I included that code in my project in Scripts folder. I take an default2.aspx page which was not included with...
1
by: thugbuddha | last post by:
Hey, I have function where it creates img element and sets id = title, When i add to index.html jquery $('#title').click(function() { alert('xx'); }); it doesn't work, why? Jscript...
1
by: simon2x1 | last post by:
when I put the following link below my page disappear leaving the bgcolor alone I include JQuery.noConflict because my slider and the lightbox are not working together and I was told that I will...
3
Frinavale
by: Frinavale | last post by:
Hi there! I have a function that handles all of the form submit functions on a page that uses the jQuery ajax api to submit the request asynchronously and then update a particular <div> on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.