Document.form.submit()不起作用

时间:2012-08-10 09:49:17

标签: javascript

我有以下内容:

<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进行更新。

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

这里有任何帮助吗?

1 个答案:

答案 0 :(得分:1)

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

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