[英]HTML Form with Required Fields, Confirmation Dialog box, and Submission Summary
我有一個HTML表單,該表單在表單標簽action =“”中使用PHP文件將表單的內容作為電子郵件發送。
我有一個用於必填字段的簡單JavaScript,以形式標簽onsubmit =“”進行調用。
提交后,我的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.