Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   Help with ALERTs. (http://www.programmingforums.org/showthread.php?t=13276)

Pyrathian Jun 3rd, 2007 11:16 PM

Help with ALERTs.
 
Hello people. I have a small exersize which I can't complete without gaining a little knowledge on a certain subject first..

The subject is Alerts. I'm trying to Validate Several feilds in a registration form. And I need to return to the user the various errors that occured while attempting to register.

It would be easier to just do it 1 alert at a time. But that would be extremely lame and unacceptable, on a professional site it would be funny.

I need to know how I can Sum up all the errors, and display them in one alert.

For example, my name is too short, and my address is too short.

An alert comes up saying
"The following errors occured:
Name too short
Address too short"

In this registry form though, there are at least 15 feilds. Does someone know of a simple way to explain how to do this?

Thanks. any links are welcome if you know of a place explaining it, I couldn't find much though. :)

DaWei Jun 4th, 2007 12:04 AM

Highlight the fields in error (for instance, change the background to light red).

Pyrathian Jun 4th, 2007 7:44 AM

I need help understanding how to do this with ALERTS. So far I have no code really besides the original HTML code. The basic idea, is that it sums up the errors and puts it in one alert. Instead of showing several alerts. That's what I need to do, and the part I havn't figured out yet.

DaWei Jun 4th, 2007 8:24 AM

Make an empty string. Each validator, if it finds an error, appends its message to the string. The concatenation operator is +.

You are going to force your user to memorize the list before he/she dismisses the alert? :rolleyes: On a professional site, that would be funny.

Pyrathian Jun 4th, 2007 8:48 AM

I know I'm just trying to get a point across :O Thanks by the way I'm trying out what you said now.

Pyrathian Jun 4th, 2007 8:57 AM

Like this?

alert ("The following errors occured: " + check);

How do you think I could write the function that that concatonates the errors into "check" ?

DaWei Jun 4th, 2007 10:13 AM

This is pseudo code, untested on a page. Presume three fields: name, address, and email. The are validated onblur or onchange, or something suitable. Variable "errors" is initially set to "The following errors occurred: \n".
:

function validateName ()
{
    ...
    if (fail) errors += "Error in name field\n";
   
}
function validateAddr ()
{
    ...
    if (fail) errors += "Error in address field\n";
}
function validateEmail ()
{
    ...
    if (fail) errors += "Error in email field\n";
}
....
....



All times are GMT -5. The time now is 2:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC