![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2007
Posts: 8
Rep Power: 0
![]() |
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. ![]() |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2007
Posts: 8
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jun 2007
Posts: 8
Rep Power: 0
![]() |
I know I'm just trying to get a point across :O Thanks by the way I'm trying out what you said now.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jun 2007
Posts: 8
Rep Power: 0
![]() |
Like this?
alert ("The following errors occured: " + check); How do you think I could write the function that that concatonates the errors into "check" ? |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|