FLASH - 检查文本输入是否为空

时间:2012-12-05 08:54:35

标签: forms flash validation

这是我第一次进行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字段做同样的事情。

感谢您的帮助,对不起我的英语。

1 个答案:

答案 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');
   }
}