Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable form auto submit on iOS device on GO button press, but hide keyboard

Posted on 2015-02-19
1
Medium Priority
?
490 Views
Last Modified: 2015-09-24
Hello,

I am having a bit of an issue with getting a form not to auto submit on iOS devices (which I have solved using the following).

function disableEnterKey(e)
{
	var key;
	if(window.event)
		key = window.event.keyCode; //IE
		else
			key = e.which; //firefox

			return (key != 13);
			
		}

Open in new window


However I also need it to then hide the on-screen keyboard which is where I am a bit stuck.

The elements of the HTML of the form are as follows:

<form role="form" method="POST" name="level1buttons" id="level1buttons">
....
<input id="notes" name="notes"  type="text" class="form-control" onKeyPress="return disableEnterKey(event)" placeholder="Other comments">
....
<button type="button" class="btn btn-black" value="Exit" onClick="autoSubmit();">Save &amp; Finish</button>

Open in new window


The input field NOTES being what causes the form to submit, presumably by running autoSubmit() which is as follows:

function autoSubmit()
{
    var formObject = document.forms['level1buttons'];
    formObject.submit();
}

Open in new window


Is there a better way to do what I am achieving? My knowledge of JavaScript is rather limited.

Thanks,

Lee
0
Comment
Question by:Lee Redhead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 40623275
greetings Lee Redhead, , ,  I do not know, or have ever heard of any javascript that can get the Operating system to change its operations, you say -  "However I also need it to then hide the on-screen keyboard which is where I am a bit stuck.", Since there are no OS changes, so then you can try and fool it into taking away the screen keyboard by dropping the Input focus (active input) with the javascript command   blur()   as in -
      document.activeElement.blur();


also you have gone to the trouble of blocking the carriage return key (number 13) in a text input, however, I have had much better results for form Submit Control by using the <form> onsubmit( )  event like -
    <form action="getpost.asp" onsubmit="return verifies(event);">

this onsubmit( )  is run for ALL of the ways a form can be submitted from the page, and Also you can use the  event  object to see which form Input had the focus then the event fired, you can verify that all inputs have an an entry, and block the submission for any reason you program into it, and you do not have to block the carriage return key in any input, if the button is touched, or any of 10 inputs press the carriage return key, then the   verifies( ) function runs. you can get the element that does the submit with   event.target   and if it is NOT a permitted submit element (by your standards) then block the submission.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question