By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

How do I prevent this action?

P: n/a
On a multi-textbox form, linked to an external js, I use onBlur to call:

function chkNum(cellname) {
var str = document.getElementById(cellname).value.toString(1 0);
if (str < 28 || str > 36) {alert("Temperature entered is out of range.");
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?

--
Ed Jay (remove M to respond by email)
Dec 21 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
On 21/12/2005 22:40, Ed Jay wrote:
[...] I use onBlur to call:

^^^^^^
Use the change event and validate in response to the submit event, too.

The blur event should be used sparingly. Too many things can cause a
control to lose focus, so it's kinder to the user to only bug them if
they /changed/ a value and entered an invalid value.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 22 '05 #2

P: n/a
Ed Jay said the following on 12/21/2005 5:40 PM:
On a multi-textbox form, linked to an external js, I use onBlur to call:

function chkNum(cellname) {
var str = document.getElementById(cellname).value.toString(1 0);
if (str < 28 || str > 36) {alert("Temperature entered is out of range.");
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?


Set the value of the textbox within range.

<input type="text" value="28" .....>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 22 '05 #3

P: n/a
Lee <RE**************@cox.net> wrote:
Ed Jay said:

On a multi-textbox form, linked to an external js, I use onBlur to call:

function chkNum(cellname) {
var str = document.getElementById(cellname).value.toString(1 0);
if (str < 28 || str > 36) {alert("Temperature entered is out of range.");
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?


Don't audit onBlur. Use onChange, instead.


Lee, Mike, Randy...Thanks very much.

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #4

P: n/a
Ed Jay wrote:
I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?


If you meant that you didn't want the error when the field is empty,
then of course:

var tmp = obj.value;

if (tmp != "" && (tmp <28 || tmp > 36))
alert("out of range");

I'm not sure why you're using toString() when you have the values. ??

Kev

Dec 22 '05 #5

P: n/a
"Kevin Darling" <kd******@basit.com> wrote:
Ed Jay wrote:
I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?
If you meant that you didn't want the error when the field is empty,
then of course:

var tmp = obj.value;

if (tmp != "" && (tmp <28 || tmp > 36))
alert("out of range");


Thanks.
I'm not sure why you're using toString() when you have the values. ??

It didn't work otherwise.

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #6

P: n/a
Ed Jay wrote:
On a multi-textbox form, linked to an external js, I use onBlur to call:

function chkNum(cellname) {
Seems you've got plenty of answers above, guess I'm a little slow but
here you go anyway...

I guess you call this something like:

<input type="text" name="textbox" onblur="chkNum('textbox');" ... >
A much better idea is to use 'this', so you call the function:

<input type="text" name="textbox" onblur="chkNum(this);" ... >
And you function statement starts:

function chkNum(cell) {
As others have said, using onblur and an alert for validation is really
annoying.

var str = document.getElementById(cellname).value.toString(1 0);
The value of an input element is always passed as a string, toString
serves no useful purpose.

var str = cell.value;

if (str < 28 || str > 36)
Even though values are passed as strings, they are type-converted to
numbers when evaluate this way so this line will work as it does now.

However, you should ensure that the values entered into the text input
were numbers in the first place. If you want to validate that they were
integers, there are plenty of examples in the archives, or use something
from here:

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#Val>

... {alert("Temperature entered is out of range.");
If there is a set range, then better to let the user know:
{ alert("Temperature must be between 28 and 36 inclusive");
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?


Allow no input at all, replace:

if (str < 28 || str > 36)
With:

if (str && (str < 28 || str > 36))


--
Rob
Dec 22 '05 #7

P: n/a
RobG <rg***@iinet.net.au> wrote:
Ed Jay wrote:
On a multi-textbox form, linked to an external js, I use onBlur to call:

function chkNum(cellname) {
Seems you've got plenty of answers above, guess I'm a little slow but
here you go anyway...

I guess you call this something like:

<input type="text" name="textbox" onblur="chkNum('textbox');" ... >


Yes.
A much better idea is to use 'this', so you call the function:

<input type="text" name="textbox" onblur="chkNum(this);" ... >

And you function statement starts:

function chkNum(cell) {
Works fine, thanks.
As others have said, using onblur and an alert for validation is really
annoying.
Understood, but I don't want to wait until a submit to notify the user. No
offense intended to doctors, but my user is a medical doctor and if I wait
to validate until a submit, the guy will stare at the screen for days
trying to figure out which cell has the invalid entry. ;-)
var str = document.getElementById(cellname).value.toString(1 0);
The value of an input element is always passed as a string, toString
serves no useful purpose.

var str = cell.value;
if (str < 28 || str > 36)


Even though values are passed as strings, they are type-converted to
numbers when evaluate this way so this line will work as it does now.

However, you should ensure that the values entered into the text input
were numbers in the first place. If you want to validate that they were
integers, there are plenty of examples in the archives, or use something
from here:

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#Val>


Yes, I'm already filtering input to assure only digits and a single
decimal.
... {alert("Temperature entered is out of range.");


If there is a set range, then better to let the user know:
{ alert("Temperature must be between 28 and 36 inclusive");

To enter the data, the User is looking at a photo with the temperature
shown. The error _should be_ obvious.
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?


Allow no input at all, replace:

if (str < 28 || str > 36)
With:

if (str && (str < 28 || str > 36))


The problem with this approach is that using onChange as my event, with no
data entered, there is no change when I go to the next cell. At least when
I click on an empty cell and then move to the next cell, there's no alert.

The other issue with using onChange is that the user need only click the
cell with the invalid entry and then click to the next cell. There's no
change, so there's no function call. I guess the final validity test will
have to catch the error.

Is there a method for returning the cursor to the errant entry when the
alert is triggered?

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #8

P: n/a
Ed Jay wrote:
RobG <rg***@iinet.net.au> wrote:

Ed Jay wrote:
[...]
As others have said, using onblur and an alert for validation is really
annoying.

Understood, but I don't want to wait until a submit to notify the user. No
offense intended to doctors, but my user is a medical doctor and if I wait
to validate until a submit, the guy will stare at the screen for days
trying to figure out which cell has the invalid entry. ;-)


OK, they're your users... but you could also consider having an area set
aside for messages to show alerts as text in the page.
[...]
... {alert("Temperature entered is out of range.");


If there is a set range, then better to let the user know:

{ alert("Temperature must be between 28 and 36 inclusive");

To enter the data, the User is looking at a photo with the temperature
shown. The error _should be_ obvious.


But it is always good to let them know why it's out of range. Error
messages are like e-mail, very impersonal and it's easy to offend people
so they get a bad impression of your program. On the other hand, smarmy
messages make me puke - over to you :-)

return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?
Allow no input at all, replace:

if (str < 28 || str > 36)
With:

if (str && (str < 28 || str > 36))

The problem with this approach is that using onChange as my event, with no
data entered, there is no change when I go to the next cell. At least when
I click on an empty cell and then move to the next cell, there's no alert.


Designing a good user interface is really tough. onchange will only
fire if the input changes, so I don't think it's the right event here.

My above suggestion was intended to be used onblur - but isn't no entry
the same as an out-of-range value? So I don't think it's a valid solution.

An alternative is to validate the entire form each time, stopping at the
first invalid entry. But this won't work if they enter a value into the
second text box first, they'll get an error that the first box is out of
range.

The other issue with using onChange is that the user need only click the
cell with the invalid entry and then click to the next cell. There's no
change, so there's no function call. I guess the final validity test will
have to catch the error.
Exactly.

I think the best method is to use in-page messages for each validated
field. That way the user can see what's invalid and what isn't, then
it's up to them to fix it. Validate again on submit.

Nearly any method has sneaky work-arounds that a user can adopt to avoid
your alerts (as you've noted) or inconsistencies with how the form is
used. Coding to prevent them all makes a rigid interface that is very
frustrating to use. If you users are doctors, hopefully they have the
intelligence to understand that if they make an error they will be
warned to fix it and that ultimately it's up to them to do it.


Is there a method for returning the cursor to the errant entry when the
alert is triggered?


You can call the focus method after displaying the alert:

...
alert("Temperature entered is out of range.");
if (cell.focus) cell.focus();
}

If used in conjunction with onblur, this will trap the user in the field
until a valid number is entered (hence it would be nice to let them know
what the valid range is).
--
Rob
Dec 22 '05 #9

P: n/a
RobG <rg***@iinet.net.au> wrote:
Ed Jay wrote:
RobG <rg***@iinet.net.au> wrote:

Ed Jay wrote:
[...]
As others have said, using onblur and an alert for validation is really
annoying.

Understood, but I don't want to wait until a submit to notify the user. No
offense intended to doctors, but my user is a medical doctor and if I wait
to validate until a submit, the guy will stare at the screen for days
trying to figure out which cell has the invalid entry. ;-)


OK, they're your users... but you could also consider having an area set
aside for messages to show alerts as text in the page.


Excellent idea.

[...]
... {alert("Temperature entered is out of range.");

If there is a set range, then better to let the user know:
{ alert("Temperature must be between 28 and 36 inclusive");
To enter the data, the User is looking at a photo with the temperature
shown. The error _should be_ obvious.


But it is always good to let them know why it's out of range. Error
messages are like e-mail, very impersonal and it's easy to offend people
so they get a bad impression of your program. On the other hand, smarmy
messages make me puke - over to you :-)


lol. I agree with you. alert("Look at the photo, dummy!") :-)
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?

Allow no input at all, replace:

if (str < 28 || str > 36)
With:

if (str && (str < 28 || str > 36))

The problem with this approach is that using onChange as my event, with no
data entered, there is no change when I go to the next cell. At least when
I click on an empty cell and then move to the next cell, there's no alert.


Designing a good user interface is really tough. onchange will only
fire if the input changes, so I don't think it's the right event here.

My above suggestion was intended to be used onblur - but isn't no entry
the same as an out-of-range value? So I don't think it's a valid solution.

An alternative is to validate the entire form each time, stopping at the
first invalid entry. But this won't work if they enter a value into the
second text box first, they'll get an error that the first box is out of
range.

The other issue with using onChange is that the user need only click the
cell with the invalid entry and then click to the next cell. There's no
change, so there's no function call. I guess the final validity test will
have to catch the error.


Exactly.

I think the best method is to use in-page messages for each validated
field. That way the user can see what's invalid and what isn't, then
it's up to them to fix it. Validate again on submit.

Nearly any method has sneaky work-arounds that a user can adopt to avoid
your alerts (as you've noted) or inconsistencies with how the form is
used. Coding to prevent them all makes a rigid interface that is very
frustrating to use. If you users are doctors, hopefully they have the
intelligence to understand that if they make an error they will be
warned to fix it and that ultimately it's up to them to do it.


Is there a method for returning the cursor to the errant entry when the
alert is triggered?


You can call the focus method after displaying the alert:

...
alert("Temperature entered is out of range.");
if (cell.focus) cell.focus();
}

If used in conjunction with onblur, this will trap the user in the field
until a valid number is entered (hence it would be nice to let them know
what the valid range is).


Good suggestions, all. Thanks much.

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #10

P: n/a
RobG <rg***@iinet.net.au> wrote:
Ed Jay wrote:
RobG <rg***@iinet.net.au> wrote:

Ed Jay wrote:
[...]
As others have said, using onblur and an alert for validation is really
annoying.


Understood, but I don't want to wait until a submit to notify the user. No
offense intended to doctors, but my user is a medical doctor and if I wait
to validate until a submit, the guy will stare at the screen for days
trying to figure out which cell has the invalid entry. ;-)


OK, they're your users... but you could also consider having an area set
aside for messages to show alerts as text in the page.
[...]
... {alert("Temperature entered is out of range.");

If there is a set range, then better to let the user know:
{ alert("Temperature must be between 28 and 36 inclusive");

To enter the data, the User is looking at a photo with the temperature
shown. The error _should be_ obvious.


But it is always good to let them know why it's out of range. Error
messages are like e-mail, very impersonal and it's easy to offend people
so they get a bad impression of your program. On the other hand, smarmy
messages make me puke - over to you :-)

return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?

Allow no input at all, replace:

if (str < 28 || str > 36)
With:

if (str && (str < 28 || str > 36))

The problem with this approach is that using onChange as my event, with no
data entered, there is no change when I go to the next cell. At least when
I click on an empty cell and then move to the next cell, there's no alert.


Designing a good user interface is really tough. onchange will only
fire if the input changes, so I don't think it's the right event here.

My above suggestion was intended to be used onblur - but isn't no entry
the same as an out-of-range value? So I don't think it's a valid solution.

An alternative is to validate the entire form each time, stopping at the
first invalid entry. But this won't work if they enter a value into the
second text box first, they'll get an error that the first box is out of
range.

The other issue with using onChange is that the user need only click the
cell with the invalid entry and then click to the next cell. There's no
change, so there's no function call. I guess the final validity test will
have to catch the error.


Exactly.

I think the best method is to use in-page messages for each validated
field. That way the user can see what's invalid and what isn't, then
it's up to them to fix it. Validate again on submit.

Nearly any method has sneaky work-arounds that a user can adopt to avoid
your alerts (as you've noted) or inconsistencies with how the form is
used. Coding to prevent them all makes a rigid interface that is very
frustrating to use. If you users are doctors, hopefully they have the
intelligence to understand that if they make an error they will be
warned to fix it and that ultimately it's up to them to do it.


Is there a method for returning the cursor to the errant entry when the
alert is triggered?


You can call the focus method after displaying the alert:

...
alert("Temperature entered is out of range.");
if (cell.focus) cell.focus();
}

If used in conjunction with onblur, this will trap the user in the field
until a valid number is entered (hence it would be nice to let them know
what the valid range is).


A bit of a problem with this scheme. Best illustration...goto
<http://www.edbj.aes-intl.com/jstest5.html>. Click on Box1, but enter no
data. Then, click Box2. If you have good eyes, you can observe the cursor
alternating between the two boxes while the alert remains on screen.

The code:

function chkNum(cell) {
var str = cell.value;
if (str.length == 0) {alert("Missing data");if (cell.focus)
cell.focus();return;}
if (str && (str < 28 || str > 36)) {alert("Temperature entered is out of
range.");if (cell.focus) cell.focus();return;}
if (str.length != 4) {alert("Enter temperature to one decimal place.");if
(cell.focus) cell.focus();
return;}
}

<form name="form1" action="">
Box1: <input type="text" name="box1" size=4 onkeypress="return
onlyDigits(event,'decOK')" onBlur="chkNum(this)">
<br>
Box2: <input type="text" name=box2 size=4 onkeypress="return
onlyDigits(event,'decOK')" onBlur="chkNum(this)">
<br><br>
<input type="submit" value="Submit">
</form>

Thoughts?

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #11

P: n/a
Ed Jay wrote:
[...]
A bit of a problem with this scheme. Best illustration...goto
<http://www.edbj.aes-intl.com/jstest5.html>. Click on Box1, but enter no
data. Then, click Box2. If you have good eyes, you can observe the cursor
alternating between the two boxes while the alert remains on screen.


Depends on which browser you are using I guess. Seems to me you are
back at the beginning - firing the validation onblur does not give a
satisfactory result.

A couple of tips: trim quotes to only what is relevant and manually wrap
code at about 70 characters (75 max) to allow for a couple of re-posts
without wrapping.

Indent code using 2 or 4 spaces, non-indented code is much harder to
read, especially if random auto-wrapping has also occurred.

I would do something more like the following (with onsubmit validation too):

<head>
<title>...</title>

<style type="text/css">
.erMsg {
color: #f00;
background-color: #fff;
font-weight: bold;
white-space: nowrap;
}
</style>

</head>
<body>
<script type="text/javascript">

function chkNum(cell)
{
var str = cell.value;
var erMsg = '';
var erEl;

// Set min and max range values
var minVal = 28.0;
var maxVal = 36.0;
var erTxt = ' from ' + minVal + ' to ' + maxVal + '.';

if (!str) {
erMsg = 'Enter a value' + erTxt;
} else if ( !validNum(str) ){
erMsg = str + ' isn\'t valid, enter a value' + erTxt;
} else if ( str < minVal || str > maxVal){
erMsg = 'Out of range. Value must be' + erTxt;
}

if ( document.getElementById
&& '' != cell.name
&& (erEl = document.getElementById(cell.name + '_er'))){
erEl.innerHTML = erMsg;
} else {
alert(erMsg);
}
}

function validNum(n){
return /^\d\d(.\d)?$/.test(n);
}

</script>

<form name="form1" action="">
Box1: <input type="text" name="box1" size="4"
onBlur="chkNum(this)"><span id="box1_er"
class="erMsg"></span><br>
Box2: <input type="text" name="box2" size="4"
onBlur="chkNum(this)"><span id="box2_er"
class="erMsg"></span><br>
<input type="submit" value="Submit">
</form>

</body>

[...]

--
Rob
Dec 22 '05 #12

P: n/a
RobG <rg***@iinet.net.au> wrote:
Ed Jay wrote:
[...]
A bit of a problem with this scheme. Best illustration...goto
<http://www.edbj.aes-intl.com/jstest5.html>. Click on Box1, but enter no
data. Then, click Box2...
..Seems to me you are
back at the beginning - firing the validation onblur does not give a
satisfactory result.


I think it's appropriate to go back to using onChange instead of onBlur,
then do a js validate onSubmit and again in my server-side script.
A couple of tips: trim quotes to only what is relevant and manually wrap
code at about 70 characters (75 max) to allow for a couple of re-posts
without wrapping.
I'm wrapping at 74 chrs.
Indent code using 2 or 4 spaces, non-indented code is much harder to
read, especially if random auto-wrapping has also occurred.
Sorry.
I would do something more like the following (with onsubmit validation too):

<head>
<title>...</title>

<style type="text/css">
.erMsg {
color: #f00;
background-color: #fff;
font-weight: bold;
white-space: nowrap;
}
</style>

</head>
<body>
<script type="text/javascript">

function chkNum(cell)
{
var str = cell.value;
var erMsg = '';
var erEl;

// Set min and max range values
var minVal = 28.0;
var maxVal = 36.0;
var erTxt = ' from ' + minVal + ' to ' + maxVal + '.';

if (!str) {
erMsg = 'Enter a value' + erTxt;
} else if ( !validNum(str) ){
erMsg = str + ' isn\'t valid, enter a value' + erTxt;
} else if ( str < minVal || str > maxVal){
erMsg = 'Out of range. Value must be' + erTxt;
}

if ( document.getElementById
&& '' != cell.name
&& (erEl = document.getElementById(cell.name + '_er'))){
erEl.innerHTML = erMsg;
} else {
alert(erMsg);
}
}

function validNum(n){
return /^\d\d(.\d)?$/.test(n);
}

</script>

<form name="form1" action="">
Box1: <input type="text" name="box1" size="4"
onBlur="chkNum(this)"><span id="box1_er"
class="erMsg"></span><br>
Box2: <input type="text" name="box2" size="4"
onBlur="chkNum(this)"><span id="box2_er"
class="erMsg"></span><br>
<input type="submit" value="Submit">
</form>

I've been playing around with both innerHTML and a hidden div to print and
erase error messages. Very similar to your scheme.

Thanks for all of your help.

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #13

P: n/a
On 22/12/2005 01:22, Ed Jay wrote:
RobG <rg***@iinet.net.au> wrote:
[snip]
As others have said, using onblur and an alert for validation is really
annoying.


Understood, but I don't want to wait until a submit to notify the user.


Which is why the change event is used as well. It will validate values
as they are entered, and the validation triggered by submission will
catch missed fields, and those that may be still invalid but unchanged.

Trapping a user with the blur event is a usability failure. If the user
tabs through the fields (or clicks from one to the other), they
shouldn't be told every single time that need to enter a valid value.

[snip]
if (str < 28 || str > 36)


Even though values are passed as strings, they are type-converted to
numbers when evaluate this way so this line will work as it does now.

However, you should ensure that the values entered into the text input
were numbers in the first place.


In general, yes, but it's not really necessary here. If they values
weren't numeric, they would be type-converted to NaN which, in a
RelationalExpression, evaluates to undefined and in turn to boolean false.

[snip]
The problem with this approach is that using onChange as my event, with no
data entered, there is no change when I go to the next cell. At least when
I click on an empty cell and then move to the next cell, there's no alert.
By design and from the user's point of view, a good thing.
The other issue with using onChange is that the user need only click the
cell with the invalid entry and then click to the next cell. There's no
change, so there's no function call. I guess the final validity test will
have to catch the error.
If that's what the user chooses to do, then yes. But, there's every
possibility that the user skipped the field to do something else first,
and has every intention to go back and change it (which is why they
should be allowed to do that unhindered).
Is there a method for returning the cursor to the errant entry when the
alert is triggered?


Yes, you can call the focus method of the INPUT element. However, if you
do that then you /must not/ use the blur event. Doing so may lead to an
infinite loop of blur events and alerts.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 22 '05 #14

P: n/a
Michael Winter <m.******@blueyonder.co.uk> wrote:
On 22/12/2005 01:22, Ed Jay wrote:
RobG <rg***@iinet.net.au> wrote:


[snip]
As others have said, using onblur and an alert for validation is really
annoying.


Understood, but I don't want to wait until a submit to notify the user.


Which is why the change event is used as well. It will validate values
as they are entered, and the validation triggered by submission will
catch missed fields, and those that may be still invalid but unchanged.

Trapping a user with the blur event is a usability failure. If the user
tabs through the fields (or clicks from one to the other), they
shouldn't be told every single time that need to enter a valid value.

[snip]
if (str < 28 || str > 36)

Even though values are passed as strings, they are type-converted to
numbers when evaluate this way so this line will work as it does now.

However, you should ensure that the values entered into the text input
were numbers in the first place.


In general, yes, but it's not really necessary here. If they values
weren't numeric, they would be type-converted to NaN which, in a
RelationalExpression, evaluates to undefined and in turn to boolean false.

[snip]
The problem with this approach is that using onChange as my event, with no
data entered, there is no change when I go to the next cell. At least when
I click on an empty cell and then move to the next cell, there's no alert.


By design and from the user's point of view, a good thing.
The other issue with using onChange is that the user need only click the
cell with the invalid entry and then click to the next cell. There's no
change, so there's no function call. I guess the final validity test will
have to catch the error.


If that's what the user chooses to do, then yes. But, there's every
possibility that the user skipped the field to do something else first,
and has every intention to go back and change it (which is why they
should be allowed to do that unhindered).
Is there a method for returning the cursor to the errant entry when the
alert is triggered?


Yes, you can call the focus method of the INPUT element. However, if you
do that then you /must not/ use the blur event. Doing so may lead to an
infinite loop of blur events and alerts.

Thanks, Mike. Your points are well made. After spending all night
contemplating the issue, they are also well taken.

--
Ed Jay (remove M to respond by email)
Dec 22 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.