Disable Go button on iPhone using JavaScript

I am creating a small form for the iPhone, and in this form I am performing JavaScript validation (backed by server validation, of course, but it is not).

As a result of this check, I turn on / off the submit button dynamically. This work is great, except that the "Go" button on the on-screen keyboard does not reflect the status of the only submit button that I have and is always on.

Can this be fixed? Can I somehow disable this Go button with JavaScript?

+4
source share
4 answers

The on-screen keyboard cannot be edited by JavaScript. You should simply cancel sending events if the form has not been confirmed.

+3
source

You can completely hide the Go button by deleting the form element. By this I mean saving your inputs and selections, but removing the <form> tags.

You can still send / confirm using jQuery, but the Go button will be replaced with the Return button.

+5
source

Flavio script works, but users may be unintuitive if the Go button is disabled.

Instead of disabling the submit button, try disabling the form submission.

 <form id="myform" onSubmit="return canSubmit(this);"> ... </form> 

JQuery method:

 $('#myform').submit(canSubmit); /* where canSubmit is a function defined as 'function canSubmit() {...}' returning true or false */ 
+4
source

use this javascript code inside the head tag, and you disable the go button for input types: text, number, tel, email.

 <script language="javascript" type="text/javascript"> <!--disable enter key / go button iphone--> function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) {return false;} if ((evt.keyCode == 13) && (node.type=="email")) {return false;} if ((evt.keyCode == 13) && (node.type=="tel")) {return false;} if ((evt.keyCode == 13) && (node.type=="number")) {return false;} } document.onkeypress = stopRKey; </script> 
+1
source

Source: https://habr.com/ru/post/1346859/


All Articles