469,958 Members | 1,904 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,958 developers. It's quick & easy.

OnChange Event

I have a javascript that will output a message telling the user that
changes were made. It halfway works. If the user enters in a number,
the TextChanged function executes and displays the "Changes Made"
message, but if the user deletes a number by using the BACKSPACE key or
the DELETE key on the keyboard, the function does not run. Am I using
the wrong event handler?
function TextChanged(){
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
<input type='text' name='txtGrossPayroll1' value='1' width='10'
onBlur='TotalPremium(7)' onkeyup='ComputePremium(1)'
onchange='TextChanged()' onkeypress='return blockNumbers(event)'/>

Thanks,
CR Junk

Aug 23 '05 #1
2 7531
ASM
crjunk wrote:
I have a javascript that will output a message telling the user that
changes were made. It halfway works. If the user enters in a number,
the TextChanged function executes and displays the "Changes Made"
message, but if the user deletes a number by using the BACKSPACE key or
the DELETE key on the keyboard, the function does not run. Am I using
the wrong event handler?
function TextChanged(){
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
<input type='text' name='txtGrossPayroll1' value='1' width='10'
onBlur='TotalPremium(7)' onkeyup='ComputePremium(1)'
onchange='TextChanged()' onkeypress='return blockNumbers(event)'/>


I think you'll have to choice between onblur and onchange
because their jobs (of event) are very close
Wich one will fire first ?

try something like that :

onfocus="truc=this.value;"
onkeypress="return blockNumbers(event);"
onkeyup='ComputePremium(1)'
onblur="TotalPremium(7);if(this.value!=truc)TextCh ange();"

--
Stephane Moriaux et son [moins] vieux Mac
Aug 23 '05 #2
crjunk wrote:
I have a javascript that will output a message telling the user that
changes were made. It halfway works. If the user enters in a number,
the TextChanged function executes and displays the "Changes Made"
message, but if the user deletes a number by using the BACKSPACE key or
the DELETE key on the keyboard, the function does not run. Am I using
the wrong event handler?
onchange should fire when the element loses focus if its value has
changed. In some circumstance it fires earlier - different
circumstances in different browsers on different elements - but its
behaviour for input elements is pretty standard.

The only key press that should cause an onchange on a text input to fire
is one that moves focus off the element.

Having both onblur and onchange on the same control may create issues,
you will need to test thoroughly to ensure consistent behaviour.
function TextChanged(){
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
<input type='text' name='txtGrossPayroll1' value='1' width='10'
onBlur='TotalPremium(7)' onkeyup='ComputePremium(1)'
onchange='TextChanged()' onkeypress='return blockNumbers(event)'/>

Thanks,
CR Junk

--
Rob
Aug 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Asit | last post: by
4 posts views Thread by Zeebra3 | last post: by
3 posts views Thread by b_naick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.