Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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>

Reply With Quote
  #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);
}

Reply With Quote
  #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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:50 AM.


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