在提交该页面之前检查表单域值 [英] Checking the form field values before submitting that page

查看:107
本文介绍了在提交该页面之前检查表单域值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了以下函数来检查start_date字段是否为空,并在单击提交按钮时显示正确的消息。但是,它将控制权转移到上一页。所以用户必须再次写入该表单上的所有其他字段。
有没有什么方法可以在提示错误信息后保留该页面,并且所有其他字段都是值。

I have written following function which checks whether start_date field is not empty and displays proper message when submit button is clicked. But then it takes the control to the previous page. So user has to write again all other fields on that form. Is there any way to stay on that page even after prompting the error message, with all other fields value.

//JavaScript
function checkform() {
    if(document.frmMr.start_date.value == "") {
        alert("please enter start_date");
        return false;
    } else {
        document.frmMr.submit();
    }
}

// HTML
<html>
    <form name=frmMr action="page1.jsp">
        Enter Start date:
        <input type="text" size="15" name="start_date" id="start_date">
        <input type="submit" name="continue" value="submit" onClick="checkform();">
    </form>
</html>

预先致谢

Thanks in advance

推荐答案

您可能想要在form标签中用 onsubmit =return checkform()替换此方法,尽管两者都可以用于点击按钮。

You may want to considering replacing this method with onsubmit="return checkform()" in the form tag instead, though both will work for clicking the button.

这篇关于在提交该页面之前检查表单域值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆