p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   alert (http://p2p.wrox.com/showthread.php?t=7678)

collie December 28th, 2003 05:21 AM

alert
 
Hi,

I am trying to write a function that returns an error message. If the user doesn't enter a valid email then an alert pops up, if the user doesn't enter a phone number then a different alert must appear. The problem is that if the user doesn't enter an email and a number then i don't want to alerts to appear. I want the error messages to appear in one alert. I tried writing the following function but it gives me the error: 'object is empty' and i think it is referring to the line alert(sat)


     function ValidateForm ()
{
var sat;
    if (document.Form1.txtEmail.value.indexOf("@")==-1)
    {
sat+="Incorrect email"
    return false;
    }


    if (document.Form1.txtMsg.value=="")
    {
sat+="Enter message"
    return false;
    }
  alert(sat)
    else
        {
    document.Form1.action="card.asp";
        }
        document.Form1.submit()
    }
*/

        </script>


Greg Griffiths December 28th, 2003 04:59 PM

Try something like :

var errors=0;
var errmsg="";

if (document.Form1.txtEmail.value.indexOf("@")==-1)
{
    errors=errors+1;
    errmsg=errmsg+"Please enter a valid Email Address.\n";
}

if (errors>0)
{
    alert("There were " + errors + " errors, they were :\n\n" + errmsg);
}


collie December 29th, 2003 02:29 AM

Thanks Greg.:)
I will try it.



All times are GMT -4. The time now is 12:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.