473,320 Members | 1,978 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,320 software developers and data experts.

body - innerText.length after onkeydown

I'm facing a problem where if I press a key in the <body> element ,of a
dhtml page, the event is actioned before the actual key has been added to
the document.

In essence, I'm aiming to capture the length of Text entered and if > 0 then
do something. Can anyone please explain how i can ensure the document is
updated before I attempt to assess the length, otherwise I am out of sync?

I hope that makes sense!

Martin
Jul 23 '05 #1
4 4846
VK
> I'm aiming to capture the length of Text entered

Text entered to where? Right to the body (over contenteditable) or to a
form control?

Jul 23 '05 #2


onkeydown triggers when the key is 'down', try instead with onkeyup,
which will trigger until the key is released UP or onkeypress which is
about the same.
Danny

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #3
ASM
Martin John Brindle wrote:
I'm facing a problem where if I press a key in the <body> element ,of a
dhtml page, the event is actioned before the actual key has been added to
the document.

In essence, I'm aiming to capture the length of Text entered and if > 0 then
do something. Can anyone please explain how i can ensure the document is
updated before I attempt to assess the length, otherwise I am out of sync?


<form>
<input type="text"
onkeydown="t=this.value"
onkeyup="if(t.length>10){
this.value=t;
alert('length allowed reached');
}">
</form>
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #4
Thanks guys. However, I've managed to hack this together and it works so I'm
happy! I take the length of the editable body and add the character provided
it's not a BACKSPACE.

<SCRIPT LANGUAGE="javascript">
<!--
var strIndex = "";

function input_onkeydown(docObj) {
var strEmpty = docObj.innerText + String.fromCharCode(event.keyCode);

if (window.event.keyCode != 8)
strEmpty.length == 0 ? strEmpty = "Y" : strEmpty = "N";
else
(strEmpty.length -1 == 0) || (strEmpty.length -2 == 0) ? strEmpty = "Y"
: strEmpty = "N";
. . .
}
-->
</SCRIPT>
<BODY id="input" onkeydown="input_onkeydown(this)">
<div name=foo contenteditable="true" align=left></div>
</BODY>
Jul 23 '05 #5

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

Similar topics

1
by: Manu Ashok | last post by:
hi this particular piece of code is not working in netscape. pls help me function getList(listfrom, listto){ var currSelect = document.forms.elements; var strid = ""; for (i = 0; i <...
4
by: keerthana_m_2003 | last post by:
Hello: is it possible to insert the value of some JavaScript variable in the body of HTML (for example the text on button, or at any part of the HTML text part). Please tell me how to do this. ...
12
by: Mark Rae | last post by:
Hi, It's easy enough for a child page to manipulate its MasterPage's header simply by modifying the MasterPage thus: <header runat="server"> .... .... </header>
1
by: PCK | last post by:
My goal is to populate the body element so that I can add an onkeydown event. <body onkeydown='x();'></body> I am currently using master/content pages. I do not want this function on every...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
5
by: JEgbert | last post by:
I am trying to hide a layer when a text box length is zero, and its just not working! It hides the content in the layer, but you still see a little 2 pixel width blip on the screen. I've spent...
5
by: GarryJones | last post by:
To show users how many characters they have left in a TEXTAREA input I have been using "taCount" from a website I googled. function taCount(visCnt) { var taObj=event.srcElement; if...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.