在提交表单之前确认msg
Confirm msg before submitting a form
我正在验证一个表单,然后通过javascript请求确认…提交时,我调用了两个函数validate() &make_confirm () .
onsubmit="return(validate() && show_alert(this));"
通过这个,我部分能够调用两个函数,但确认部分不能正常工作,我必须将其重定向到另一个页面,同时按下OK,但它不去,请帮助我
验证,Make_sure()函数如下:
function validate() {
if(document.getElementById('cname').value == '')
{
alert('Please enter your name');
document.getElementById('cname').focus();
return false;
}
else if(document.getElementById('address').value == '')
{
alert('Please enter your address');
document.getElementById('address').focus();
return false;
}
else if(document.getElementById('city').value == '')
{
alert('Please choose your city');
document.getElementById('city').focus();
return false;
}
else if(document.getElementById('state').value == '')
{
alert('Please enter your state');
document.getElementById('state').focus();
return false;
}
function make_sure() {
if(confirm("Do you really want to do this?"))
document.forms[0].submit();
else
return false;
}
使用一个函数进行验证和确认,并设置表单的action
以将表单当前页面重定向到另一个页面
function validateAndConfirm() {
if( isEmpty(id('cname').value) ) {
alert('Please enter your name');
id('cname').focus();
return false;
}
else if( isEmpty(id('address').value) ) {
alert('Please enter your address');
id('address').focus();
return false;
}
else if( isEmpty(id('city').value) ) {
alert('Please choose your city');
document.getElementById('city').focus();
return false;
}
else if( isEmpty(id('state').value) ) {
alert('Please enter your state');
id('state').focus();
return false;
} else {
if(confirm("Do you really want to do this?")) {
document.forms[0].submit();
}
else {
return false;
}
}
}
function isEmpty(val){
return (typeof val == 'undefined' || val === undefined || val == null || val.length <= 0) ? true : false;
}
// this function help to simplify you writing : document.getElementById to just id
function id(sid){
return document.getElementById(sid);
}
相关文章:
- 按钮字段确认点击不'不起作用
- 删除确认对话框在第一次单击时不起作用
- 在表单完成并确认密码之前,请禁用提交按钮
- 在asp.net中确认是或否消息
- javascript确认对话框有时会不断出现
- 是否可以用变量确认提示警报
- 检测在确认页面导航时单击了哪个按钮
- 确认前执行
- 如何为javascript方法放入jquery确认对话框
- jQuery:确认.html()是否可添加
- 是否可以将JXBrowser显示的JS确认对话框的结果返回到调用它的JS部分
- 在离开Aurelia.js上的页面之前,我如何要求用户进行确认
- 火灾在卸载前确认警报仅适用于外部站点
- 如何在批准露天共享中工作流的审核步骤之前添加确认对话框
- Rails:将表单字段值添加到数据确认消息中
- 需要确认我对Servlet vs RESTful网页的理解's的差异
- 无法在PHP中找到确认按钮
- 从确认框中预填充输入文本框
- HiddenField从服务器更改的javascript值在客户端确认
- 在提交表单之前确认msg