繁体   English   中英

带有必填字段,“确认”对话框和提交摘要的HTML表单

[英]HTML Form with Required Fields, Confirmation Dialog box, and Submission Summary

  1. 我有一个HTML表单,该表单在表单标签action =“”中使用PHP文件将表单的内容作为电子邮件发送。

  2. 我有一个用于必填字段的简单JavaScript,以形式标签onsubmit =“”进行调用。

  3. 提交后,我的PHP文件返回了表单的摘要。

我需要添加的只是一个简单的确认对话框。 但是我很难弄清楚该怎么做。 (对不起,我应该更加聪明!)我可能可以将JavaScript添加到所需的字段代码中,但是不确定如何执行此操作。 这是我现有的代码:

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(drop_point,"Please choose a Drop Point")==false)
{drop_point.focus();return false;}
if (validate_required(your_name,"Please enter your Name")==false)
{your_name.focus();return false;}
if (validate_required(email,"Please enter your Email Address")==false)
{your_name.focus();return false;}
}

}

任何帮助,将不胜感激! 谢谢!

你可以用

confirm("Are you sure you want to submit?");

根据用户选择返回True或False

这里有一些样品。 这是你想要的?

编辑:

function validate_required(field,alerttxt)
{
   with (field)
        {
         if (value==null||value=="")
            {
              alert(alerttxt);return false;
            }

        }
return confirm("Are you want to submit the form");
}

Shoban让我走了,这就是我的解决方案:

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(drop_point,"Please choose a Drop Point")==false)
{drop_point.focus();return false;}
if (validate_required(first_name,"Please enter your First Name")==false)
{first_name.focus();return false;}
if (validate_required(last_name,"Please enter your Last Name")==false)
{last_name.focus();return false;}
if (validate_required(drop_point_date,"Please enter the Drop Point Date")==false)
{drop_point_date.focus();return false;}
if (validate_required(email,"Please enter your Email Address")==false)
{email.focus();return false;}
if (validate_required(order_confirm,"Please confirm your order")==false)
{order_confirm.focus();return false;}
}
return confirm("Do you want to submit the form");
}

而且完美!

非常感谢! 活到老,学到老!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM