checking if a value changed in onblur event handler

L

laredotornado

Hi,

Using the onblur handler in a text field, how can I check if the value
was changed from what was originally there prior to the user focussing
on the text field?

Thanks, - Dave
 
D

David Mark

Hi,

Using the onblur handler in a text field, how can I check if the value
was changed from what was originally there prior to the user focussing
on the text field?

Thanks, - Dave

Store the value in the onfocus handler and check against it in onblur.
 
D

David Mark

Why you use the onblur,but not use onkeydown or onchange?

Because that isn't what the OP asked for. onkeydown doesn't enter
into it, but you could use onchange instead of onfocus and onblur.
 
S

sandip.bhoi

Because that isn't what the OP asked for. onkeydown doesn't enter
into it, but you could use onchange instead of onfocus and onblur.


when onchange event is invoked ?
is it invoked when the actual value of text field is
changed by user interaction (by key board/ mouse - copy paste)?
what if, the value of text field is changed by the script and not by I/
O device?

I am changing the value of text field by a java script
(asynchronous) and i want that event catched when value changed.
"onchange" does not work at that time.

Is there any way to detect the change?
 
S

sandip.bhoi

No, but if it is your code that is doing it, why not do whatever you need to
do after setting the value.

Hello Dave
Actually my code is not changing the value, I am using a
third party javascript
Utility(html-editor: GPL ). Which changes the value. I can't change
the utility code(GPL).
Therefore I wanted to detect that change.

Thanks.
 
D

David Mark

Hello Dave
Actually my code is not changing the value, I am using a
third party javascript
Utility(html-editor: GPL ). Which changes the value. I can't change
the utility code(GPL).
Therefore I wanted to detect that change.

Unless the editor can do a callback on this change or can be
subclassed, I don't know what you can do.
 
R

RobG

Hi,

Using the onblur handler in a text field, how can I check if the value
was changed from what was originally there prior to the user focussing
on the text field?

Compare the control's value to its defaultValue. It works in Safari,
Firefox and Opera at least, you should check IE:


<input type="text" id="xx" value="blah" onclick="
alert(this.defaultValue + ' : ' + this.value);
">
<input type="button" value="change it" onclick="
document.getElementById('xx').value='foo';
">

However, when to check is something of a mystery if you change its value
by script. You could use polling with setInterval, but that is a very
expensive exercise in terms of consuming browser resources.
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top