473,503 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onKeyDown in form doesn't work with DIV and innerHTML

I have come across a problem with the onKeyDown event in some of my forms.
I'm using onKeyDown in <form> as a standard method to open my help screen
system throughout my system, but I have discovered that If I have a
<div></div> section somewhere and then load the contents of it from another
file using innerHTML after the main window is loaded, the onKeyDown event
doesn't trigger any more.

I'm using IE6 and the structure is:

<body onLoad=getDiv()>
<form onKeyDown=getHelp();>
<div id=pagebody></div>
</form>
</body>

where the getDiv function sets pagebody.innerHTML to something (which works
just fine). In pages where I don't use the <div>'s the getHelp() function
starts fine.

Any idea how I can work around this problem?

Thanks!
Brgds
iv**@tda.no
Jul 23 '05 #1
2 5915
Iver Erling Årva wrote:
I have come across a problem with the onKeyDown event in some of my forms.
I'm using onKeyDown in <form> as a standard method to open my help screen
system throughout my system, but I have discovered that If I have a
<div></div> section somewhere and then load the contents of it from another
file using innerHTML after the main window is loaded, the onKeyDown event
doesn't trigger any more.

I'm using IE6 and the structure is:

<body onLoad=getDiv()>
<form onKeyDown=getHelp();>
<div id=pagebody></div>
</form>
</body>
You should always enclose attribute values in quotes. It is not
mandatory in HTML if the attribute value contains *only* letters (a-z
and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII
decimal 46), underscores (ASCII decimal 95), and colons (ASCII
decimal 58).

However, the W3C recommends using quotation marks even when it is
possible to eliminate them. The script attributes in the code above
contains semi-colons and brackets that should always be in quotes.

<URL:http://www.w3.org/TR/html4/intro/sgmltut.html>

where the getDiv function sets pagebody.innerHTML to something (which works
just fine). In pages where I don't use the <div>'s the getHelp() function
starts fine.


Even without quoted attribute values, I could not replicate your
issue in IE 6, so perhaps your problems are elsewhere.

Here is my test script (sans quotes):

<script type="text/javascript">
function getDiv(){
document.getElementById('pagebody').innerHTML='bla h blah blah';
}
function getHelp(){
var now = new Date();
document.getElementById('blah').innerHTML = now;
}
window.onload = getDiv;
</script>

<form onKeyDown=getHelp(); action=>
<input type=text>
<div id=pagebody></div>
</form>
<span id=blah></span>
--
Rob
Jul 23 '05 #2
Agreed!

You example works here as well, so it must be something else.

Can't see what though. when I had it all in one file it was ok, but when I
moved out that section and placed it in a <div> it doesn't work any more.
I'll have to look into it a bit further. Btw, I'm using the active-x
Msxml2.XMLHTTP to send the other file back into innerHTML using it's
responseText property. Wonder if that could have to do with it...

Thanks!
iv**@tda.no

"RobG" <rg***@iinet.net.auau> skrev i melding
news:42**********************@per-qv1-newsreader-01.iinet.net.au...
Iver Erling Årva wrote:
I have come across a problem with the onKeyDown event in some of my
forms. I'm using onKeyDown in <form> as a standard method to open my help
screen system throughout my system, but I have discovered that If I have
a <div></div> section somewhere and then load the contents of it from
another file using innerHTML after the main window is loaded, the
onKeyDown event doesn't trigger any more.

I'm using IE6 and the structure is:

<body onLoad=getDiv()>
<form onKeyDown=getHelp();>
<div id=pagebody></div>
</form>
</body>


You should always enclose attribute values in quotes. It is not
mandatory in HTML if the attribute value contains *only* letters (a-z
and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII
decimal 46), underscores (ASCII decimal 95), and colons (ASCII
decimal 58).

However, the W3C recommends using quotation marks even when it is
possible to eliminate them. The script attributes in the code above
contains semi-colons and brackets that should always be in quotes.

<URL:http://www.w3.org/TR/html4/intro/sgmltut.html>

where the getDiv function sets pagebody.innerHTML to something (which
works just fine). In pages where I don't use the <div>'s the getHelp()
function starts fine.


Even without quoted attribute values, I could not replicate your
issue in IE 6, so perhaps your problems are elsewhere.

Here is my test script (sans quotes):

<script type="text/javascript">
function getDiv(){
document.getElementById('pagebody').innerHTML='bla h blah blah';
}
function getHelp(){
var now = new Date();
document.getElementById('blah').innerHTML = now;
}
window.onload = getDiv;
</script>

<form onKeyDown=getHelp(); action=>
<input type=text>
<div id=pagebody></div>
</form>
<span id=blah></span>
--
Rob

Jul 23 '05 #3

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

Similar topics

72
5137
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
3
2379
by: news.microsoft.com | last post by:
Hi all. I have a problem eith OnKeyDown it work fine when on the form there are nothing, but when I am adding toolbar it does not work properly, I receive Keys.Up event for 2 second time Can...
4
4974
by: Udi | last post by:
Hi All, MyRichEdit is derived from RichTextBox. I'm overriding OnKeyDown. I'm trying to handle the TAB key but without printing it in the edit box: protected override bool IsInputKey(Keys...
1
1734
by: firenet | last post by:
21 function js_reply_msg(node,g_id,u_id,par_id) 22 { 23 node.innerHTML="<FORM><TEXTAREA name=\"msg_con\"><\/TEXTAREA><br><INPUT type=\"submit\" value=\"reply\"><\/FORM>" 24 ...
4
8051
by: Dan Michael Heggå | last post by:
Hi, I've working on inplace-editing. My problem is the following: This works in all browsers: myDiv.innerHTML = "<p>...</p>"; but this doesn't work in IE: myDiv.innerHTML =...
3
5629
by: Ralph | last post by:
Hi I have small function to generate my form controls: function buildInput(sType, vValue, vId, sName, sLabel){ var oInput = null; var oLabel = document.createElement('label'); var oCont =...
0
1113
by: =?Utf-8?B?Q0dX?= | last post by:
I have a .NET 1.1 application which uses several grids of text boxs (in repeaters and datagrids) for entering arrays of time values. I use onkeydown to allow users to navigate through the grids...
0
1168
by: CGW | last post by:
I posted this in a .NET general newsgroup, but then found this group and I think it would be more appropriately posted here. Even though the problem is partially with client side behavior, I'm...
3
1678
by: bdbeames | last post by:
Ok I have a form validation problem that I need one of you javascript ninja s to help me with. The following is a form with the javascript that I have used for the last year or two to validate. ...
0
7086
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
7280
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,...
0
7330
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...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.