• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jQuery submit() does not work but DOM.submit() does

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider my code:





Whenever I use the old DOM object configuration of

document.getElementById('pollForm')

, the submittal takes place with no problem, however, if I use jQuery object configuration

$('#pollForm').submit()

, no submittal takes place.  There are no errors in the console to reflect what is wrong, just that absolutely nothing happens.

What could possibly be going wrong here? I am confused.

Thanks
 
Saloon Keeper
Posts: 15447
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know that no submit takes place?
 
Phillip Powell
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should be going to "poll_process.asp" .  When I use document.getElementById('pollForm'), that's exactly what happens
 
Stephan van Hulst
Saloon Keeper
Posts: 15447
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I'm not sure what causes this. However, you could just call the submit() function on the DOM element directly, by unwrapping it from the jQuery object:

By the way, why are you still using jQuery? These days, jQuery is slowly becoming obsolete in preference of just using plain JavaScript.
 
Phillip Powell
Ranch Hand
Posts: 39
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually found a solution in the interim:

All I had to do was to remove the "onSubmit" attribute from $('#pollForm') beforehand for the submit() to work:



Thanks for the suggestion though of $('#pollForm')[0] (or I assume also $('#pollForm').get(0) )
 
Stephan van Hulst
Saloon Keeper
Posts: 15447
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the update!
 
Saloon Keeper
Posts: 27708
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:
By the way, why are you still using jQuery? These days, jQuery is slowly becoming obsolete in preference of just using plain JavaScript.



Oh? While the browser-dependent warts that jQuery smooths out are less common these days, I thought it still simplified AJAX and stuff like that. Then again, haven't compared lately.

Note: the onSubmit() function should return true or false. That allows it to veto (cancel) the submit. Before actually removing it, check to see if there's some condition you should be meeting to allow the function to return true. If there is no return statement value in the onSubmit(), then the onSubmit() is defective, so removing it probably would be the best solution. And, I should add, that means that the original page code has a bug  in it that could make submits unpredictable.
 
Stephan van Hulst
Saloon Keeper
Posts: 15447
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Oh? While the browser-dependent warts that jQuery smooths out are less common these days, I thought it still simplified AJAX and stuff like that.


The preferred way to perform AJAX requests from JavaScript is by using the Fetch API.
 
Phillip Powell
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, I definitely use Fetch, especially in my React component's that need o chain to a back-end ASP page that performs dB work and delivers JSON t the front end
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic