473,387 Members | 1,757 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.

running a function with onKeyDown

morning!

i want to run a javascript function when I enter a key in a form text input by using onKeyDown

everything runs perfectly except the function only executes after the 2nd key stroke (not 1st key stroke, as I would expect it to)

maybe onKeyDown isn't the appropriate event or maybe i am doing something else wrong?

here's my html bit

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="dogname2" class="formtextinput" id="inputter" onKeyDown="hidecontent(brad)" onBlur="unhidecontent(this)" /> 
  2.  
  3. <span id="brad"> Bradd </span>
  4.  
and here's the javascript

Expand|Select|Wrap|Line Numbers
  1. function hidecontent(el) {
  2.     var elementcontent = document.getElementById("brad")
  3.     var inputtercontent = document.getElementById("inputter")
  4.     if (inputtercontent.value!="") elementcontent.style.cssText = "visibility:hidden"
  5.  
  6. }
  7.  
  8. function unhidecontent(el) {
  9.     var elementcontent = document.getElementById("brad")
  10.     if (el.value=="") elementcontent.style.cssText = "visibility:normal"
  11.  
  12. }
  13.  
Nov 29 '11 #1

✓ answered by Dormilich

maybe onKeyDown isn't the appropriate event
you’re absolutely right there. onkeydown the value is not yet updated (i.e. it is still empty). use either onkeyup or onkeypress.

4 2453
Dormilich
8,658 Expert Mod 8TB
maybe onKeyDown isn't the appropriate event
you’re absolutely right there. onkeydown the value is not yet updated (i.e. it is still empty). use either onkeyup or onkeypress.
Nov 29 '11 #2
oh duh..onkeyup worked (though in the event I press a key and keep holding it it doesn't execute the script until i release..so i get around this by using both onkeydown AND onkeyup)..thanks!
Nov 29 '11 #3
Dormilich
8,658 Expert Mod 8TB
what about onkeypress then?

edit: it’s visibility: visible;
Nov 29 '11 #4
thanks..
onkeypress has the same problem as onkeydown
onkeyup & onkeydown work well when i run both
Nov 30 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: ruca | last post by:
Hi, How can I force to run a function when a popup window close's??? This function it's present in parent window. Can I run it after popup window close's??? How can I do that??? --
5
by: Roger Withnell | last post by:
I'm using the following code to start a function on key down. document.onkeydown = OnKeyDown; function OnKeyDown() { vKeyCode = event.keyCode; ..code... }
3
by: Rico | last post by:
Hello, I have a generic process that logs errors from different sources. When I call this code, I'd like to also submit the name of the function or sub that is raising the error without having...
11
by: cyberdwarf | last post by:
Hi, Here's a weird one! Is there a known way to determine the name of the currently running Sub or Function in VBA code? I'm trying to build a generic error-trapping funtion, to avoid...
14
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So,...
3
by: Basilisk96 | last post by:
Suppose I have a function that may run for a long time - perhaps from several minutes to several hours. An example would be this file processing function: import os def processFiles(startDir):...
1
eboyjr14
by: eboyjr14 | last post by:
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere! // ==UserScript== // @name iGoogle Suggest //...
15
by: BinaryGirl23 | last post by:
Hello, I'm sure this is such a simple question I didn't even want to bother posting but for the life of me I just can't get it to work : ( I have a button that toggles "Select All" and "Select...
2
by: mageshwar | last post by:
hi, i have using three functions to scan registry keys (like emptykeys,applicationpatherrors).once the function starts from my button click event, i cant...
2
by: ildiff | last post by:
How I can run a function written in plpgsql as superuser when I'm logged into the database as normal user with a restrict access to tables?
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.