使用 Java 脚本在 Android 上提交表单

submitting a form on android using java script

本文关键字:提交 表单 Android Java 脚本 使用      更新时间:2023-09-26

我使用以下javascript代码来validate/submit我的表单:

function SendForm()  {
            var formlist = document.getElementById ("formlist");
            var buttonRadios = document.getElementsByName ("film");
            var selected = false;
            for (var i = 0; i < formationRadios.length; i++) {
                if (formationRadios[i].checked) {
                    selected = true;
                    break;
                }
            }
            if (selected) {
                 document.formlist.submit ();
            }
            else {
           //nothing to do
            }            
        }

在 HTML 端:

<form  method="post" name="formlist"  action="films.php" OnChange="SendForm();">
...
<input type="radio" name="film" id="spman" value="spman" required="required"><label for="spman">Spider Man</label>
...
<select class="required" name="date" id="date">
<option selected value="13-05-2012">13 May 2012</option>
...
</select>
</form>

这适用于安卓下的火狐测试版,但不适用于安卓默认浏览器。它也适用于火狐桌面浏览器。

你能告诉我它有什么问题吗,我没有错误 inf 火虫控制台.

更新:

我终于发现了问题,它不是来自代码,而是来自单击标签时选中单选框的iPhone/iPad错误,以获取更多信息:

http://v4.thewatchmakerproject.com/blog/how-to-fix-the-broken-ipad-form-label-click-issue/

谢谢大家的帮助。

从 Android 2.2 开始,内置浏览器不支持通过 document 对象访问表单(如 document.name_of_your_form.submit() )。尝试以下可能性之一:

id属性:

.HTML

<form id="formlist">

JavaScript

var formlist = document.getElementById("formlist");

name属性

.HTML

<form name="formlist">

JavaScript

var formlist = document.forms["formlist"];

var formlist = document.formlist;