OnChange Event

C

crjunk

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
 
A

ASM

crjunk said:
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)TextChange();"
 
R

RobG

crjunk said:
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.
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top