Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: onchange for input type=text watching something other than value


Message #1 by "Tim Heilman" <tim.heilman@e...> on Tue, 16 Oct 2001 01:48:40
Write it off to my enthusiasm for this newfound support medium, but I'm 
replying to inform myself I fixed my own problem:

Field the onblur event instead and do manually the test for whether the 
value has changed from what it was before.

Still, the fact that IE isn't considering the input type=text's *value* 
when deciding whether the value has been changed and onchange should be 
thrown smells funny to me.

-Tim

> Hi folx!
> 
> Here's the deal: I've got an input type="text" with an initial 
> value, "a".  A behavior is attached via an in-line style attribute which 
> causes a validation routine to be bound to the onchange event for the 
> input.  For this example, suppose "a" is valid and "b" is invalid.
> 
> I type into the input element, "b", and then blur the input by clicking 
> outside it.  The onchange event fires, the validation routine runs and 
> finds that the user has set the input's value to the invalid 
string "b".  
> The routine displays an error alert and resets the value of the input 
> to "a".   This change is reflected on screen in the box and in the DOM, 
> verified with an alert of the input's value member field.
> 
> Now then, being the plucky end user that I am, I select the text in the 
> box *again*, enter "b" *again*, and (fizzle) the onchange event doesn't 
> fire.  If I had entered anything other than "b", (including "a", which 
was 
> what was displayed there already) and then blur the input, the onchange 
> event fires.  It even fires when I focus and blur the input without 
> changing its value.
> 
> So my guess at what's happening is that somewhere the invalid string "b" 
> is being kept around even after the value is reset to "a" in javascript, 
> and it is against that value that a comparison is made to see if the 
value 
> of the input changed, and so an onchange needs to be fired.  My question 
> is, how can I inform the input that the value has been changed 
> programmatically rather than via user input and that it should consider 
> this new value the one to compare against upon blur to determine if the 
> value of the input changed?
> 
> Things tried already:
> 
> Re-focusing and re-blurring (in javascript) the input after the change 
> back to "a".
> 
> Re-firing an onchange event (in javascript, within the onchange handler) 
> after the change back to "a" (in this case, the validation testing 
against 
> value succeeds, and both instances of the onchange handler terminate).
> 
> Setting the value with a this.createTextRange().text = "a" instead of 
> this.value = "a".
> 
> -Tim Heilman
> 
> p.s. I'm working on MS IE 5.5 SP2 under Windows 2000 Advanced Server

  Return to Index