onKeyDown in form doesn't work with DIV and innerHTML

I

Iver Erling Årva

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
(e-mail address removed)
 
R

RobG

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

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='blah 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>
 
I

Iver Erling Årva

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!
(e-mail address removed)
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top