473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 7742
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
2
by: F. Da Costa | last post by:
Hi, I'm trying to call/ mimic an onchange function/ event after a user has clicked a checkbox. In response to which a buncch of other ones need to be checked as well. The caveat is that each of...
2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
3
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select...
4
by: auslandt | last post by:
I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<function>" attribute against the password element. Here is an example page of the...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.