473,387 Members | 2,436 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,387 software developers and data experts.

OnKeyUp event does not work

I have problem to get onkeyup event. If we put the event in HTML
statement like -

"<input name=field1 size=16 onkeyup="javascript:function1();>"

it works.

If we put in JavaScript code like this
var oElmt = document.createElement("input");
:
oElmt.onkeyup = function () {javascript:function1() };
or
oElmt.onkeyup = "javascript:function1()";

It will work sometimes, and failed sometimes. Most of the time I need
to switch to another field and back, to make the event working.

Anybody experienced this problem before?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
2 18414
Evan Wong wrote:
I have problem to get onkeyup event. If we put the event in HTML
statement like -

"<input name=field1 size=16 onkeyup="javascript:function1();>"

it works.

If we put in JavaScript code like this
var oElmt = document.createElement("input");
:
oElmt.onkeyup = function () {javascript:function1() };
or
oElmt.onkeyup = "javascript:function1()";

It will work sometimes, and failed sometimes. Most of the time I need
to switch to another field and back, to make the event working.

Anybody experienced this problem before?


Yes, when you try to assign a string to what is a function reference, it
tends not to work too well. Use:

<body onload="test();">
<form name="myFormName" id="myFormId">
</form>
<script type="text/javascript">
function test() {
var a = document.createElement('input');
// assign the reference to function1 to the onkeyup event
a.onkeyup = function1;
document.forms['myFormName'].appendChild(a);
// or document.getElementById('myFormId').appendChild(a) ;
}
function function1() {
alert('keyup');
}
</script>
</body>

Just as a side note:

oElmt.onkeyup = function() { javascript:function1(); };

should work, but "javascript:" in that example is simply a label that
serves no purpose, and you lose the ability to refer to have "this" in
function1() refer to the element.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
My findings on this problem. Actually the original code works.
However, when the screen is loaded, my code will set focus on that text
box that has onkeyup event set. If I type in the text right away, the
onkeyup event is not fired. If I click on the text box (the same text
box), the onkeyup event is fired and the function1 will be executed for
every keystroke.

I have tried to use .focus() and .select() to set focus on the field,
and the behavior is the same. Any idea?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Trent | last post by:
Hi. I know the basic way to assign event handlers: <input onKeyUp="processEvent(event)" /> But how do I assign a function to the onKeyUp event in *javascript* that can access the event...
2
by: greg | last post by:
hello i would like to apply an onkeyup event to every element of my form in order to do that, i would use the array form.elements, doing something like that : ...
2
by: **Developer** | last post by:
I have a usercontrol that contains the following. To my surprise the form containing this control get KeyUp events. Help says that for KeyPress setting e.Handled = True suppresses KeyPress...
3
by: Brad | last post by:
The first text on my form is a numeric field. I have a javascript that runs on this field for onkeyup (validate the key strokes and modifies fields on the screen) but when I do this and have the...
5
by: fei.liu | last post by:
Hello, in the application I am developing, I am having trouble to synchronize event triggered actions using 'lock(ob){...};' technique. Here is a outline of my code: class C{ int x = 0; public...
13
by: Lee | last post by:
I have this function that doesn't work. I pass it the td element and an id, and it makes an input field inside the td. That part workds. What doesn't work is that I want to add an "onkeyup" on...
6
by: kodt | last post by:
I have a form with 4 text input fields. The last one is the total of the previous three fields and should automatically calculate this value when a user enters data into any of the first 3. ...
2
by: mc | last post by:
Can someone suggest how I would add a new trigger such that when the JS event onkeyup in a textbox the updatePanel refreshes? If not could someone sugest how I could onkepup in a Textbox, refresh...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.