phonegap android GO button to not submit form

2019-09-07 14:33发布

I'm writing an app with Phonegap and I have a register form that is sent through ajax.
It works fine when you hit the register button and execute the formcheck() function. However, when I hit the GO button from my android phone it submits the form instead of going through the formcheck() process. I tried:

<form id="RegForm" onsubmit="formcheck();return false;">

My form has no proper submit button but a button like this:

<input type="button" id="submitbtn" onclick="formcheck()"/>

I also tried to create a new OnSubmitForm() function that calls the formcheck() one but with no avail.
Thank you for helping.

2条回答
We Are One
2楼-- · 2019-09-07 15:01

Simply ensure your form tag is:

<form type='submit' onsubmit='return false;'></form>

This makes the submit action not do anything.

If you also need to hide the keyboard refer to How can I hide the Android keyboard using JavaScript?. A simple onsubmit='hideKeyboard(); return false;' will take care of this.

查看更多
Luminary・发光体
3楼-- · 2019-09-07 15:04

Found it!

1) Add this to the JS section:

$(document).ready(function() {
    $("#YourFormName").submit(function() {
    FormCheck();
    return false;
    });
});

function FormCheck() {
... validation process here ...
}

2) Make sure to include a Submit button in your form .. ( <input type="submit" )

Hope it'll help others so my 5 hour trying & testing time won't go wasted :)

查看更多
登录 后发表回答