Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 28th, 2003, 05:21 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>

  #2 (permalink)  
Old December 28th, 2003, 04:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

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);
}

  #3 (permalink)  
Old December 29th, 2003, 02:29 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Greg.:)
I will try it.



Similar Threads
Thread Thread Starter Forum Replies Last Post
custom alert kanoorani Javascript How-To 1 May 5th, 2007 07:26 AM
alert continuation mcauliff Other Programming Languages 0 February 1st, 2007 09:15 AM
alert darkhalf Javascript 3 November 18th, 2005 12:56 PM
Alert Message ferfish Classic ASP Basics 1 May 16th, 2004 06:43 PM
alert function mahulda ASP.NET 1.0 and 1.1 Basics 5 April 9th, 2004 11:05 PM





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