Html表单提交空值

时间:2014-08-30 10:02:05

标签: html html5 jsp

这是我的JSP页面:

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html;charset=utf-8" />
    <title>Entry Form</title>
    <link href="../css_res/style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <div id="MongoFORM">
        <h1>Add New Entries To Database</h1>
        <form action='../restful-services/errorops/PUSH2DB' onsubmit='this.submit();this.reset();return false;' method="post">
            <fieldset>
                <label for="ErrorName">Error Name:</label>
                <input required type="text" name="ErName" id="ErrorName" placeholder="Enter the Error Name" />

                <label for="ErrorCause">Error Cause:</label>
                <input required type="text" name="ErCause" id="ErrorCause" placeholder="Enter generic cause" />

                <label for="ErrorResolution">Error Resolution:</label>
                <input required type="text" name="ErResolution" id="ErrorResolution" placeholder="Enter generic resolution" />

                <label for="TechnicalDat">Technical Data:</label>
                <input required type="text" name="TlDat" id="TechnicalDat" placeholder="Enter error code base info (JSON)" />
                <br>
                <br>
                <input type="submit" class="large default" value="POST TO DB!" />
            </fieldset>
        </form>
    </div>

    </body>
    </html>

我的问题是,当我点击 POST TO DB!按钮时,会提交空值。但是,当 onsubmit =&#39; this.submit(); this.reset(); return false;&#39; 选项被删除时,不会发生这种情况。有人可以指导我解决方案吗?

1 个答案:

答案 0 :(得分:0)

onsubmit()在表单提交之前运行,因此表单在提交之前会重置