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

OnChange Event

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.