B. Fleming B. Fleming - 3 years ago 193
Javascript Question

Why does the jQuery .submit() event not appear to trigger on iPads?

I'm currently running into an issue where I have a form that needs to have its default submit behavior interrupted and replaced with an Ajax call. My current setup appears to work for all other desktop and mobile devices (including iPhones!), but consistently fails for iPads. Specifically, jQuery's

doesn't appear to trigger at all. Placing an
call between the
return false;
statements seems to indicate that the code block is never reached. I've also tried switching the submit button to a normal button and submitting on click, and switching to the
on('submit', functon(){...});
syntax to no avail.

Any solutions or ideas as to possible causes?

HTML structure:

<form id="targetForm" action="">
<!--inputs go here-->
<input type="submit" value="Submit"/>

Javascript structure:

$(document).ready(function() {
$('#targetForm').submit(function(event) {
//Ajax call goes here
return false;

Answer Source

It turns out that the problem existed in an unrelated function defined outside of the $(document).ready() event where a variable declaration was not terminated by a semicolon and lacked the var keyword. It threw no errors on any other devices, but caused the entire external JS file to fail to execute.

Edit, more information: It appears to be an issue with whatever JS engine is being used on iPads. For some reason, any small technically incorrect syntax issue (it even fails if you use default parameter values for some reason!) anywhere in your script file will prevent any of the JS from running. Their engine seems to be incredibly strict about very precisely meeting very specific syntax standards and punishes you severely with failing errors if you don't perfectly conform to them.

In short: My login issue is resolved.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download