这是我第一次进行FLASH表单验证,而且我是FLASH的新手。 我有以下操作:(AS 2.0)
bSubmit.onRelease = function()
{
valiForm();
}
function valiForm()
{
var sMessage = "Name: " + tName.text + "\nE-mail: " + tEmail.text + "\nPhone: " + tPhone.text;
lvSend = new LoadVars();
lvReply = new LoadVars();
var thanks = "Thanks " + tName.text + "your message has been sent";
lvSend.msg = sMessage;
lvSend.address = "myemail@ex.ex";
tName.text = "";
tEmail.text = "";
tPhone.text = "";
lvReply.onLoad()
{
tDone.text = thanks;
}
lvSend.sendAndLoad('/templates/t3976/mail.php', lvReply, 'POST');
}
现在在我发送表单之前,我想检查tName
字段是否为空,如果它是某种方式的警报,如果它是好的,那么提交表单。我也想对nPhone
字段做同样的事情。
感谢您的帮助,对不起我的英语。
答案 0 :(得分:0)
最简单的方法是比较IF中的String
if(tName.text != ""){
// proceed form code here
}
在你的情况下
bSubmit.onRelease = function()
{
valiForm();
}
function valiForm()
{
if(tName.text != "" && tPhone.text != ""){
var sMessage = "Name: " + tName.text + "\nE-mail: " + tEmail.text + "\nPhone: " + tPhone.text;
lvSend = new LoadVars();
lvReply = new LoadVars();
var thanks = "Thanks " + tName.text + "your message has been sent";
lvSend.msg = sMessage;
lvSend.address = "myemail@ex.ex";
tName.text = "";
tEmail.text = "";
tPhone.text = "";
lvReply.onLoad()
{
tDone.text = thanks;
}
lvSend.sendAndLoad('/templates/t3976/mail.php', lvReply, 'POST');
}
}