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

2 text box validations cause loop trap

P: n/a
I have back to back text boxes used to create university account numbers. I'm
actually creating them with a script so they can create as many account
numbers as they need.

<edited and cut down script>
<input type="text" size="5" name="fund_1" onBlur="checkact(this)">
<input type="text" size="5" name="org_1" onBlur="checkact(this)">"

function checkact(entry){
if (!Is_In_Format( entry.value, "dddddd")){
alert("Format: 123456");
entry.focus();
}
}
It works fine UNLESS...they enter the wrong format in "fund_1" and click
the "org_1" text box. They get an alert message (because "fund_1" is wrong)
and the script moves the focus back to "fund_1" which gives them an alert
message becuse they did not properly fill out "org_1"...well, you see where
I'm going with this.

How do you handle this type of thing?
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
In article <ui***************************@news.ks.uiuc.edu> , abbylee26
@hotmail.com enlightened us with...
It works fine UNLESS...they enter the wrong format in "fund_1" and click
the "org_1" text box. They get an alert message (because "fund_1" is wrong)
and the script moves the focus back to "fund_1" which gives them an alert
message becuse they did not properly fill out "org_1"...well, you see where
I'm going with this.

How do you handle this type of thing?


How do *I* handle it? I only validate on form submission, not on blur,
because I've had numerous problems with onblur (cross-browser).

How might you handle it?
Blanks don't fire blur handlers, then check fields again in the form's
onSubmit (assuming/if blanks aren't allowed).

onBlur="if (this.value&&this.value.length>0) checkact(this)"

--
--
~kaeli~
If a book about failures doesn't sell, is it a success?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2

P: n/a
Lee
Abby Lee said:

I have back to back text boxes used to create university account numbers. I'm
actually creating them with a script so they can create as many account
numbers as they need.

<edited and cut down script>
<input type="text" size="5" name="fund_1" onBlur="checkact(this)">
<input type="text" size="5" name="org_1" onBlur="checkact(this)">"

function checkact(entry){
if (!Is_In_Format( entry.value, "dddddd")){
alert("Format: 123456");
entry.focus();
}
}
It works fine UNLESS...they enter the wrong format in "fund_1" and click
the "org_1" text box. They get an alert message (because "fund_1" is wrong)
and the script moves the focus back to "fund_1" which gives them an alert
message becuse they did not properly fill out "org_1"...well, you see where
I'm going with this.

How do you handle this type of thing?

By never, ever, validating onBlur. Use onChange, instead.

Jul 20 '05 #3

P: n/a
Lee <RE**************@cox.net> writes:
Abby Lee said:

I have back to back text boxes used to create university account numbers.
I'm
actually creating them with a script so they can create as many account
numbers as they need.

<edited and cut down script>
<input type="text" size="5" name="fund_1" onBlur="checkact(this)">
<input type="text" size="5" name="org_1" onBlur="checkact(this)">"

function checkact(entry){
if (!Is_In_Format( entry.value, "dddddd")){
alert("Format: 123456");
entry.focus();
}
}
It works fine UNLESS...they enter the wrong format in "fund_1" and click
the "org_1" text box. They get an alert message (because "fund_1" is
wrong)
and the script moves the focus back to "fund_1" which gives them an alert
message becuse they did not properly fill out "org_1"...well, you see
where
I'm going with this.

How do you handle this type of thing?

By never, ever, validating onBlur. Use onChange, instead.


Funny thing...using the onChange "entry.focus();" no longer works.
Jul 20 '05 #4

P: n/a
kaeli <ti******@NOSPAM.comcast.net> writes:
In article <ui***************************@news.ks.uiuc.edu> , abbylee26
@hotmail.com enlightened us with...
It works fine UNLESS...they enter the wrong format in "fund_1" and click
the "org_1" text box. They get an alert message (because "fund_1" is
wrong)
and the script moves the focus back to "fund_1" which gives them an alert

message becuse they did not properly fill out "org_1"...well, you see
where
I'm going with this.

How do you handle this type of thing?


How do *I* handle it? I only validate on form submission, not on blur,
because I've had numerous problems with onblur (cross-browser).

How might you handle it?
Blanks don't fire blur handlers, then check fields again in the form's
onSubmit (assuming/if blanks aren't allowed).

onBlur="if (this.value&&this.value.length>0) checkact(this)"


I understand what you are saying...however, I must varify they are using a 6
digit number for other parts of the form to work for them before the page is
submited.
Jul 20 '05 #5

P: n/a
In article <ui***************************@news.ks.uiuc.edu> , abbylee26
@hotmail.com enlightened us with...


Funny thing...using the onChange "entry.focus();" no longer works.


It has something to do with the event bubbling - I forget the exact
cause, but it's why I didn't use onChange. :)

Try modifying your function and call to

<input type="text" size="5" name="fund_1" id="fund_1" onBlur="checkact
(this.id)">

function checkact(entry){
if (document.getElementById) {
e = document.getElementById(entry);
if (!Is_In_Format( e.value, "dddddd")){
alert("Format: 123456");
e.focus();
}
}
}

Assumes your clients have DOM browsers, though. Mine had NN4 for the
longest time, and this won't work in that.

--
--
~kaeli~
Synonym: the word you use in place of a word you can't
spell.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #6

P: n/a
kaeli <ti******@NOSPAM.comcast.net> writes:
In article <ui***************************@news.ks.uiuc.edu> , abbylee26
@hotmail.com enlightened us with...


Funny thing...using the onChange "entry.focus();" no longer works.


It has something to do with the event bubbling - I forget the exact
cause, but it's why I didn't use onChange. :)

Try modifying your function and call to

<input type="text" size="5" name="fund_1" id="fund_1" onBlur="checkact
(this.id)">

function checkact(entry){
if (document.getElementById) {
e = document.getElementById(entry);
if (!Is_In_Format( e.value, "dddddd")){
alert("Format: 123456");
e.focus();
}
}
}

Assumes your clients have DOM browsers, though. Mine had NN4 for the
longest time, and this won't work in that.


Thank you.
It's so nice that I'm creating this application for our intranet...everyone
has IE6.
Jul 20 '05 #7

P: n/a
In article <ui***************************@news.ks.uiuc.edu> , abbylee26
@hotmail.com enlightened us with...

Thank you.
It's so nice that I'm creating this application for our intranet...everyone
has IE6.


I know, I love that. :)
We have NN6 and IE6.
It's nice to know everyone has to have certain browsers. I have a lot
more leeway.
Although I test my stuff in Mozilla and Opera 7 too just for kicks
sometimes. I have learned some valuable things doing that. JIC I ever
get a job where it ISN'T intranet. heh

--
--
~kaeli~
Local Area Network in Australia:... the LAN down under.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.