Document.form.submit() 不起作用

Document.form.submit() not working

本文关键字:不起作用 submit form Document      更新时间:2023-09-26

>我有以下内容:

<form action="file.php" method="post" enctype="multipart/form-data"  name='form' id='form'>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center"  style="BORDER-RIGHT: #fe03b4 1px solid; BORDER-TOP: #fe03b4 1px solid; BORDER-LEFT: #fe03b4 1px solid; BORDER-BOTTOM: #fe03b4 1px solid">
        <tr>
            <td style="margin-left: 3px">
                <b><font color="#f803f8" size="1">Eyes</font></b>
            </td>
            <td>
                <select size="1" name="eyes" class="input" id="eyes" style="BACKGROUND-COLOR: #f7ed79; COLOR: #000000; font-family: Arial; font-size: 10px; width:150px;">`
                    <option selected="selected" value="">Select</option>
                    <option value="1"<? if ($eyes=="1") echo "selected"; ?>>Blue</option>
                    <option value="2"<? if ($eyes=="2") echo "selected"; ?>>Green</option>
                </select>
            </td>
        </tr>
    </table>
    <br />
    <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center"  style="BORDER-RIGHT: #fe03b4 1px solid; BORDER-TOP: #fe03b4 1px solid; BORDER-LEFT: #fe03b4 1px solid; BORDER-BOTTOM: #fe03b4 1px solid">
        <tr>
            <td style="margin-left: 3px">
                <b><font color="#f803f8" size="1">Description</font></b>
            </td>
            <td>
                <textarea rows='5' name='description'  cols='120'><? echo "$description"; ?></textarea>
            </td>
        </tr>
    </table>
    <br />
    <table width="100%" border="0" align="center">
        <tr>
            <td  align="center">
                <input name='Update' type='submit' onClick="if(document.form.eyes.value == ''){ alert('Eyes Color?'); document.form.eyes.focus(); return false; } else 
                if(document.form.description.value==''){ alert('Description?'); document.form.description.focus(); return false; } else
                { document.form.submit(); parent.scrollTo(0,0); }" value='Update' style="width:100%; font-size:10px" />
            </td>
        </tr>
    </table>
</form>

第一个警报(眼睛)有效,但第二个警报没有给我警报,即使没有插入文本,它也会保存。

数据库中的 EYES 列定义为 0,然后我可以选择选项 1 或 2 进行更新。

如果以前没有保存,是否可以更新数据库中的文本字段?换句话说,数据库中的文本列为 NULL(未保存文本),我尝试在没有保存的情况下进行更新。

这里有任何帮助吗?

这是因为,按钮的类型是提交。 如果要手动控制提交,请将其更改为按钮。或者改用表单提交事件,在提交事件中验证表单,如果表单无效,则取消提交。

http://msdn.microsoft.com/en-us/library/ie/ms536972(v=vs.85).aspx