473,657 Members | 2,996 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=getHe lp();>
<div id=pagebody></div>
</form>
</body>

where the getDiv function sets pagebody.innerH TML 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 5940
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=getHe lp();>
<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.innerH TML 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.getEle mentById('pageb ody').innerHTML ='blah blah blah';
}
function getHelp(){
var now = new Date();
document.getEle mentById('blah' ).innerHTML = now;
}
window.onload = getDiv;
</script>

<form onKeyDown=getHe lp(); 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.ne t.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=getHe lp();>
<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.innerH TML 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.getEle mentById('pageb ody').innerHTML ='blah blah blah';
}
function getHelp(){
var now = new Date();
document.getEle mentById('blah' ).innerHTML = now;
}
window.onload = getDiv;
</script>

<form onKeyDown=getHe lp(); 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
5188
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 complete in connection with attendance at a seminar. After spending more than 15 minutes on it, I clicked on the submit button - and nothing happened. Looking round the pages on Javascript form validation that Google produced for me (well,...
3
2391
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 anyone help me ? thanks
4
4988
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 keyData) { switch (keyData) {
1
1746
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 node.nextSibling.nextSibling.innerHTML="" 25 } My thought is that when i clicked a link,the js function generate the Form,then get the input and deal with it.
4
8062
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 = "<form>...</form>";
3
5634
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 = document.createElement('span'); var oText = document.createTextNode(sLabel); oInput = document.createElement('<input type="'+ sType +'" name="'+ sName +'" />');
0
1138
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 using arrow keys. I'm attempting to upgrade to .NET 2.0, but that particular functionality appears to be broken now. The actual javascript function is quite long and really irrelevant since the problem appears to be with the onkeydown event firing...
0
1184
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 attempting to deal with it in my VB code behind. Here's my post... 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...
3
1689
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. It works quite nicely and I like the way it works. The problem is I am working on a site where the html needs to validate using STRICT. This form doesn't validate with STRICT because I use a name on the form and not and id. Could someone show me...
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.