Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 3rd, 2007, 10:16 PM   #1
Pyrathian
Newbie
 
Join Date: Jun 2007
Posts: 8
Rep Power: 0 Pyrathian is on a distinguished road
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.
Pyrathian is offline   Reply With Quote
Old Jun 3rd, 2007, 11:04 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Highlight the fields in error (for instance, change the background to light red).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 4th, 2007, 6:44 AM   #3
Pyrathian
Newbie
 
Join Date: Jun 2007
Posts: 8
Rep Power: 0 Pyrathian is on a distinguished road
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.
Pyrathian is offline   Reply With Quote
Old Jun 4th, 2007, 7:24 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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? On a professional site, that would be funny.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 4th, 2007, 7:48 AM   #5
Pyrathian
Newbie
 
Join Date: Jun 2007
Posts: 8
Rep Power: 0 Pyrathian is on a distinguished road
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 is offline   Reply With Quote
Old Jun 4th, 2007, 7:57 AM   #6
Pyrathian
Newbie
 
Join Date: Jun 2007
Posts: 8
Rep Power: 0 Pyrathian is on a distinguished road
Like this?

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

How do you think I could write the function that that concatonates the errors into "check" ?
Pyrathian is offline   Reply With Quote
Old Jun 4th, 2007, 9:13 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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";
}
....
....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:52 PM.

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