How can I prevent the Go button on iPad/iPhone from posting the form

后端 未结 6 1497
北海茫月
北海茫月 2020-12-31 00:52

I have a dynamic form that is to be displayed using an iPad.

This form has a couple of radio buttons and some text fields and one submit button.

In an iPad t

6条回答
  •  感情败类
    2020-12-31 01:00

    I found a solution to my problem.

    The base to the problem is that Safari mobile ignores onsubmit="return false" on buttons, it only works on forms.

    Setting onsubmit="return false;" on the form, making a normal button (not submit) and setting onclick="form.submit()".

    Ex.

    ... //Other fields here

    The Go button does not trigger a normal button, only submit buttons. Since the form has onsubmit="return false;" it will not post.

    The button on the other hand, when clicked triggers the onclick="form.submit();" which overrides the onsubmit on the form.

    This solution seems to work in any browser reliably.

提交回复
热议问题