Alert????

D

dimple.nshah

Hello,

I am trying to figure out the functionality of alert in javascript. I
have a form with about 5 fields. Each field has a check on whether the
information entered is valid. If the user enters an invalid
information, a alert box pops up. My problem is, if I say OK on the
alert box, the entire page is refreshed. Is there any way in which
only that particular field (in which invalid information is entered)
is refreshed and the remaining fields are as they were?

Thanks in advance.
Dimple.
 
J

Jeremy J Starcher

I am trying to figure out the functionality of alert in javascript. I
have a form with about 5 fields. Each field has a check on whether the
information entered is valid. If the user enters an invalid information,
a alert box pops up. My problem is, if I say OK on the alert box, the
entire page is refreshed. Is there any way in which only that particular
field (in which invalid information is entered) is refreshed and the
remaining fields are as they were?


Without code, I can only guess as to the issue.

My first guess is not returning false from an event handler.

That said, Alert tends to be an awkward and annoying way to handle entry
errors, ESPECIALLY if done on a field-by-field basis.
 
E

Evertjan.

wrote on 04 mrt 2008 in comp.lang.javascript:
I am trying to figure out the functionality of alert in javascript. I
have a form with about 5 fields. Each field has a check on whether the
information entered is valid. If the user enters an invalid
information, a alert box pops up. My problem is, if I say OK on the
alert box, the entire page is refreshed. Is there any way in which
only that particular field (in which invalid information is entered)
is refreshed and the remaining fields are as they were?

Yes and no.

Yes it is possible and No that would not be called refresh.
The discussion however is meaningless without you showing your code.
Please only show the essential part.
 
D

dimple.nshah

 wrote on 04 mrt 2008 in comp.lang.javascript:


Yes and no.

Yes it is possible and No that would not be called refresh.
The discussion however is meaningless without you showing your code.
Please only show the essential part.

Thanks for replying...

I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
var validDate1 = document.Form.Date_Today.value;

var dateFormat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var array1 = validDate1.match(dateFormat); // is the format ok?

if (array1 == null) {
alert("Today's Date: Not in a valid format.")
return false;
}

// parse date into variables

month1 = array1[1];
day1 = array1[3];
year1 = array1[4];

if (month1 < 1 || month1 > 12) { // check month range
alert("Today's Date: Month must be between 1 and 12.");
return false;
}

if (day1 < 1 || day1 > 31) {
alert("Today's Date: Day must be between 1 and 31.");
return false;
}

if ((month1==4 || month1==6 || month1==9 || month1==11) && day1==31) {
alert("Today's Date: Month "+month1+" does not have 31 days!")
return false;
}

if (month1 == 2) { // check for february 29th
var isleap1 = (year1 % 4 == 0 && (year1 % 100 != 0 || year1 % 400 ==
0));
}

if (day1>29 || (day1==29 && !isleap1)) {
alert("Today's Date: February " + year1 + " does not have " + day1 + "
days!");
return false;
}
 
T

Tom

I am trying to figure out the functionality of alert in javascript. I
have a form with about 5 fields. Each field has a check on whether the
information entered is valid. If the user enters an invalid information,
a alert box pops up. My problem is, if I say OK on the alert box, the
entire page is refreshed. Is there any way in which only that particular
field (in which invalid information is entered) is refreshed and the
remaining fields are as they were?


Without code, I can only guess as to the issue.

My first guess is not returning false from an event handler.

That said, Alert tends to be an awkward and annoying way to handle entry
errors, ESPECIALLY if done on a field-by-field basis.[/QUOTE]

I agree, the alert() function is okay for debugging your own code, but there's
more current and cleaner looking ways to generate error messages. You can add
messages inside the HTML document and would have full control over the
appearance of the text.

Tom
 
E

Evertjan.

wrote on 04 mrt 2008 in comp.lang.javascript:

[please do not quote signatures on usenet]
Thanks for replying...

I am actually writing date validation. Here is the scripting part:

The below is just part of a function that returns true or false.

Either way it does not show if what is done to the page or input field
and that seems to be your Q?

I see no alert box code.
// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
var validDate1 = document.Form.Date_Today.value;

var dateFormat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var array1 = validDate1.match(dateFormat); // is the format ok?

if (array1 == null) {
alert("Today's Date: Not in a valid format.")
return false;
}

// parse date into variables

month1 = array1[1];
day1 = array1[3];
year1 = array1[4];

if (month1 < 1 || month1 > 12) { // check month range
alert("Today's Date: Month must be between 1 and 12.");
return false;
}

if (day1 < 1 || day1 > 31) {
alert("Today's Date: Day must be between 1 and 31.");
return false;
}

if ((month1==4 || month1==6 || month1==9 || month1==11) && day1==31) {
alert("Today's Date: Month "+month1+" does not have 31 days!")
return false;
}

if (month1 == 2) { // check for february 29th
var isleap1 = (year1 % 4 == 0 && (year1 % 100 != 0 || year1 % 400
=0));
}

if (day1>29 || (day1==29 && !isleap1)) {

Every month? So August 31 should fail?
alert("Today's Date: February " + year1 + " does not have " + day1 + "
days!");
return false;
}

See John Stockton's pages for more consize tests.
<http://www.merlyn.demon.co.uk/js-dates.htm>
 
D

dimple.nshah

 wrote on 04 mrt 2008 in comp.lang.javascript:





[please do not quote signatures on usenet]
Thanks for replying...
I am actually writing date validation. Here is the scripting part:

The below is just part of a function that returns true or false.

Either way it does not show if what is done to the page or input field
and that seems to be your Q?

I see no alert box code.




// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
var validDate1 = document.Form.Date_Today.value;
var dateFormat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var array1 = validDate1.match(dateFormat); // is the format ok?
if (array1 == null) {
alert("Today's Date: Not in a valid format.")
return false;
}
// parse date into variables
month1 = array1[1];
day1 = array1[3];
year1 = array1[4];
if (month1 < 1 || month1 > 12) { // check month range
alert("Today's Date: Month must be between 1 and 12.");
return false;
}
if (day1 < 1 || day1 > 31) {
alert("Today's Date: Day must be between 1 and 31.");
return false;
}
if ((month1==4 || month1==6 || month1==9 || month1==11) && day1==31) {
alert("Today's Date: Month "+month1+" does not have 31 days!")
return false;
}
if (month1 == 2) { // check for february 29th
var isleap1 = (year1 % 4 == 0 && (year1 % 100 != 0 || year1 % 400
=0));
}
if (day1>29 || (day1==29 && !isleap1)) {

Every month? So August 31 should fail?
alert("Today's Date: February " + year1 + " does not have " + day1 + "
days!");
return false;
}

See John Stockton's pages for more consize tests.
<http://www.merlyn.demon.co.uk/js-dates.htm>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


I have a check before that alert (if month==4 || month==6.......)...
Hence, August 31 would not fail...
 
D

dimple.nshah

On Tue, 04 Mar 2008 18:55:29 GMT, Jeremy J Starcher wrote...





I agree, the alert() function is okay for debugging your own code, but there's
more current and cleaner looking ways to generate error messages. You can add
messages inside the HTML document and would have full control over the
appearance of the text.

Tom
--
NewsGuy Leap Year Savings!
Free Month with 3, 6 or 12 Month Unlimited Accountshttp://newsguy.com/overview.htm- Hide quoted text -

- Show quoted text -


You mean I need to check if the date is in proper format, inside HTML
itself??? Any suggestions how to I do it without making it
complicated???
 
D

Doug Miller

I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
var validDate1 =3D document.Form.Date_Today.value;

Why the devil are you asking the user to type today's date into a form? The
computer _already_knows_ what today's date is. No need to ask the user.
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
That said, Alert tends to be an awkward and annoying way to handle entry
errors,

IBTD. It is the most efficient and most compatible one.
ESPECIALLY if done on a field-by-field basis.

That is a design error also found in other UI solutions that cannot be
attributed to window.alert(). Displaying messages the the user is what
this method was designed for.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Doug said:
[...] [email protected] said:
I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)

Date input formats on an international medium like the Web should follow
internationally standardized formats, such as ISO 8601 (YYYY-MM-DD), or
provide a control for every date component.
Why the devil are you asking the user to type today's date into a form? The
computer _already_knows_ what today's date is. No need to ask the user.

Nonsense. "The computer" "knows" only the data that has been put into it,
which are dictated by the capabilities of hardware, software, and the person
that has provided the original data. However, if we assume that the user is
capable of keeping the system clock in a nearly correct state, that value
can serve as a basis for further input.

BTW, you NetNews user agent is broken as it did not decode the QP-declared
=3D properly.


PointedEars
 
D

Doug Miller

Doug said:
[...] [email protected] said:
I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)

Date input formats on an international medium like the Web should follow
internationally standardized formats, such as ISO 8601 (YYYY-MM-DD), or
provide a control for every date component.

Irrelevant. No form should ever ask for today's date.
Nonsense. "The computer" "knows" only the data that has been put into it,
which are dictated by the capabilities of hardware, software, and the person
that has provided the original data.

Unfamiliar with NTP, are you?
However, if we assume that the user is
capable of keeping the system clock in a nearly correct state, that value
can serve as a basis for further input.

Pedant. This is of course going to be the case the vast majority of the time,
as you are doubtless aware. In any event it's certainly easy enough to display
what the computer thinks (is that better?) is today's date as a default value.

The point remains that requiring the user to type in *any* information that
can be determined in advance by the software, especially something so simple
and straightforward as today's date, is asinine.
 
L

Lasse Reichstein Nielsen

Thomas 'PointedEars' Lahn said:
IBTD. It is the most efficient and most compatible one.

Compatible, yes. Efficient, definitly no.

The problem with alerts is that you should collect all errors and only
make one alert. More than one alert at a time is horrible, and only
reporting one error at a time is a waste of the user's time.

But when the user dismisses the alert, the error messages become
unavailable. So the user has to remember the errors in order to fix
them.

It is much better to display the error messages as part of the page that
they apply to. Preferably also highlighting the parts that need to be
corrected.
That is a design error also found in other UI solutions that cannot be
attributed to window.alert(). Displaying messages the the user is what
this method was designed for.

Messages, yes. Messages that the user needs to remember in order to
continue using the page correctly, should be avoided.
The more things they need to remember, the worse, so reporting multiple
errors at a time is even worse.

/L
 
E

Evertjan.

Doug Miller wrote on 05 mrt 2008 in comp.lang.javascript:
Irrelevant. No form should ever ask for today's date.

You "ever" is wrong,
there are many instances where it is apropriate to do so.

In medicine it is one of the first questions asked to estimate the
client/patient's desorientation. It could be used to correct errors with
the computer's clock off line, or to set a virtual reality time in a
simulation.

Speaking about a form [or a letter] asking is a strong humanisation,
a form is just a instrument of asking, but I like that. ;-)
 
T

Thomas 'PointedEars' Lahn

Lasse said:
Compatible, yes. Efficient, definitly no.

Definitely yes. You overlook what is involved in creating an alert message
box and what is involved in creating the alternatives
The problem with alerts is that you should collect all errors and only
make one alert.

Nonsense. Why confuse the user with things they are not concerned with at
the moment? People learn better one step at a time.
More than one alert at a time is horrible, and only
reporting one error at a time is a waste of the user's time.
ACK.

But when the user dismisses the alert, the error messages become
unavailable. So the user has to remember the errors in order to fix
them.

See below. I think you are giving users too less credit.
It is much better to display the error messages as part of the page that
they apply to. Preferably also highlighting the parts that need to be
corrected.

Which would you require a bunch of feature tests so that it does not break.
Very efficient, indeed.
Messages, yes. Messages that the user needs to remember in order to
continue using the page correctly, should be avoided.

I don't think so. Users who are capable of remembering where the Back
button is should be able to remember what the last message said. It is
instead the message text that has to be kept simple and yet precise enough
so that remembering it becomes easy.
The more things they need to remember, the worse, so reporting multiple
errors at a time is even worse.

I did not debate that.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Doug said:
Doug said:
[...] (e-mail address removed) wrote:
I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
Date input formats on an international medium like the Web should follow
internationally standardized formats, such as ISO 8601 (YYYY-MM-DD), or
provide a control for every date component.

Irrelevant. No form should ever ask for today's date.

Non sequitur. The date input format could very well become the display
format here.
Unfamiliar with NTP, are you?

I am not. Apparently most users are. There have been many times that I
have observed users not running their systems with the current local time,
even if they were using Windows XP.
[flame snipped]


PointedEars
 
T

Tim Streater

Thomas 'PointedEars' Lahn said:
Doug said:
Doug Miller wrote:
[...] (e-mail address removed) wrote:
I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
Date input formats on an international medium like the Web should follow
internationally standardized formats, such as ISO 8601 (YYYY-MM-DD), or
provide a control for every date component.

No, I want it in my local format.
Non sequitur. The date input format could very well become the display
format here.

In addition, it might not be today's date I need.
I am not. Apparently most users are. There have been many times that I
have observed users not running their systems with the current local time,
even if they were using Windows XP.

Of course. Why does anyone think most users will even have heard of NTP,
much less have any idea what it's for or how to use it.
 
T

Thomas 'PointedEars' Lahn

Tim said:
Doug said:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Doug Miller wrote:
[...] (e-mail address removed) wrote:
I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
Date input formats on an international medium like the Web should follow
internationally standardized formats, such as ISO 8601 (YYYY-MM-DD), or
provide a control for every date component.

No, I want it in my local format.

Irrelevant. Several million other people have ISO 8601 as their local
format. However, L10n could include an option for user-defined display.
The point was, it is a bad idea for a Web application to use the localized
format *by default*.


PointedEars
 
T

Tim Streater

Thomas 'PointedEars' Lahn said:
Tim said:
Doug Miller wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Doug Miller wrote:
[...] (e-mail address removed) wrote:
I am actually writing date validation. Here is the scripting part:

// Date Validation for Today's Date (date should be in mm/dd/yyyy
form)
Date input formats on an international medium like the Web should follow
internationally standardized formats, such as ISO 8601 (YYYY-MM-DD), or
provide a control for every date component.

No, I want it in my local format.

Irrelevant. Several million other people have ISO 8601 as their local
format. However, L10n could include an option for user-defined display.
The point was, it is a bad idea for a Web application to use the localized
format *by default*.

Why? I would call it a good idea for the page to consult my local
settings for date format display.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top