[Javascript] required entry field

Mckinney, Lori K lkmckinn at ingr.com
Wed Mar 26 16:27:42 CST 2003


Create a test page containing two input text boxes and one div.  On each input, add an onblur and onfocus event handler that just appends a message about which control it was and which event.  Tab into the first input and you will get a message that the first one got focus.  Tab out of the control and you will get a message that the first got blur and the second got focus.  If you then change the onblur of the first one to output the message then reset the select back to the first control, if you get what I get with IE6, you will get 

one focus

then tab out of one and get

one blur
two focus
two blur
one focus


<input type=text id=one onblur="div1.innerHTML+='<BR>one blur';this.select();this.focus();" onfocus="div1.innerHTML+='<BR>one focus'"><br>
<input type=text id=two onblur="div1.innerHTML+='<BR>two blur'" onfocus="div1.innerHTML+='<BR>two focus'"><br>
<div id=div1></div>

Using one of the functions gives the same results, only with an additional alert.

-----Original Message-----
From: Michael Dougherty [mailto:Michael_Dougherty at PBP.com]
Sent: Wednesday, March 26, 2003 04:14 PM
To: javascript at LaTech.edu
Subject: RE: [Javascript] required entry field


I'm thinking of VB/VFP's lostfocus() method which can return false to
prevent the loss of focus.  Consider this scenario (which is closer to what
i'm doing)

<input name='CCExpireMonth' onBlur='validMonth(this)' />
<input name='CCExpireYear' onBlur='validYear(this)' />

function validMonth( obj ) {
	if( <invalid>) {
		alert("invalid month");
		obj.select();
		obj.focus();
		}
	}

function validYear( obj ) {
	if( <invalid> ) {
		alert("invalid year");
		obj.select();
		obj.focus();
		}
	}

  After the object's BLUR, the method fires.  Does this mean that during the
execution of the method that no control has focus?  When the obj.focus()
statement is executed, will another onBlur be executed first or is there no
currently focused control to Blur at this point?  (hopefully this question
is understandable, because it's late in the day  <g>)


More information about the Javascript mailing list