Any Way To Detect Certain Keys OnKeyDown?
May 14, 2010
What I need is something as such (based on previous thread): I have a textfield and I want to limit the input to only numbers, letters and caps.
So the code is:
<input onkeydown="return testChars(event)" type="text" .../>
function testChars(e){
var keyCode = e.keyCode;
if(e.shiftKey && keyCode==53){
return false;
} //block "%"
//HERE BLOCK EVERYTHING THATS NOT a Letter, caps and numbers
if ( (keyCode > 64 && keyCode < 91) ||(keyCode > 96 && keyCode < 123) )//Letters and Caps{
return true;
}else if ( keyCode > 47 && keyCode < 58 )//numbers{
return true;
}}
The problem however using the onkeydown is that I would need to cater for every single possibility of them using SHIFT+1=*, SHIFT+2, SHIFT+3 etc. which would take forever. And I cant block Shift because they might use it for capitalizing letters.
View 14 Replies
ADVERTISEMENT
Dec 10, 2010
I am trying to assign the left and right arrows, but I cannot get the code to work. It would be great to get some help--I am a newbie to coding.
[Code]...
View 1 Replies
View Related
Oct 21, 2011
I am trying to setup a textbox to only accept specific keys. The problem is, some of the Function keys are reading as the same values as letters.Ex.
112 - F1 - p
113 - F2 - q
114 - F3 - r[code]....
Is there another way to allow the function keys without enabling all matching letters as well?
View 2 Replies
View Related
Oct 18, 2009
I am making a php/mysql epos system for my shop which will be run from a browser on my shop PC. I have large buttons which I would like to be able to 'click' by pressing something like the F-buttons at the top of the keyboard. Is it possible to override the standard button shortcuts for a web page. This is only going to be on my shop computer so accessibility is not a problem.
View 2 Replies
View Related
Jul 31, 2001
I am looking form a script which when a key is presses, it scrolls a selected frame down or up (depending on the key).
View 7 Replies
View Related
Jul 23, 2005
I have set window.onkeydown which works fine. One of my shortcut keys is "n", so a user can not type "n" in forms. How do I solve that?
View 5 Replies
View Related
Jan 7, 2010
I'm trying to submit the form normally as well as by pressingCtrlEnter. Yepp, the same task.What I'm doing is the following:
var validator=$
"#myform"
.validate
[code]...
View 1 Replies
View Related
May 9, 2011
I have a form with many, many, many 'input type="text"' elements in it. I'd like to be able to dynamically add an 'onKeyDown' event listener. Here's what I've got, so far (I know it's wrong.)
Code:
function addEventToElement(formName,tagName,typeName,eventName,eventAction) {
thisForm = (typeof formName == 'string') ? document.getElementById(formName) : '' ;
thisTag = (typeof tagName == 'string') ? tagName : '' ;
thisType = (typeof typeName == 'string') ? typeName : '' ;
thisEvent = (typeof eventName == 'string') ? eventName : '' ;
thisAction = (typeof eventAction == 'string') ? eventAction : '' ;
if(thisForm != "") { // If elements are in a form, make sure ONLY those elements are affected
elem = new Array(); elem = thisForm.getElementsByTagName(thisTag); // array of all items of [tag]
alert(elem.length);
if(thisType != "") {
for(j=0;j<elem.length;j++) {
if(elem[j].type != thisType) { elem.splice(j,1); } // If a type is specified, remove tags that do not have a type attribute
}
}
}
else { // Otherwise, any/all elements in a document/body will be affected
elem = new Array(); elem = document.getElementsByTagName(thisTag); // array of all items of [tag]
if(thisType != "") {
for(j=0;j<elem.length;j++) {
if(elem[j].type != thisType) { elem.splice(j,1); } // If a type is specified, remove tags that do not have a type attribute
}
}
}
if((thisEvent != "") && (thisAction != "")) {
for(i=0;i<elem.length;i++) { // All elements are picked - let's apply some attributes
document.getElementById(elem[i].id).addEventListener(thisEvent,thisAction,false)
}
}
}
HTML Code:
addEventToElement('form_name','input','text','keydown','return numbersOnly(event,this);');
View 7 Replies
View Related
Jul 23, 2005
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:
View 2 Replies
View Related
Jun 14, 2011
I have the below code to block the view source but its not working for me.
<html>
<head>
<script language="javascript">
function onKeyDown() {
// current pressed key
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
if (event.ctrlKey && (pressedKey == "c" ||
pressedKey == "v")) {
// disable key press processing
event.returnValue = false;
} }
// onKeyDown
</script>
</head>
<body>
<DIV align=center> .....
View 9 Replies
View Related
Feb 24, 2010
I want to use an onkeydown() on my web site and the web site to know which key I pressed. Specifically know I pressed the arrow keys and store which key was pressed in a variable. Must work on all browsers.
View 1 Replies
View Related
Oct 12, 2011
I am trying to find a way to get more than one characters pasted on html text field (input type=text), using onkeydown or onkeypress, I am NOT interested in onkeyup(it works), so please do not suggest me this solution. Also I am not interested in Jquery, I do not like to use it. I need solution to work with all browsers.
I am able to do that if you type one character, by taking the character of the event, but till now I am unable to get group of characters come from the paste (ctrl+V) or by mouse.You can look at Facebook search menu that shows auto complete results, it works on events: onkeydown and onkeypress and you notice that you get the result before you release your finger, try to paste something (more than one character) and you get the result before releasing finger, how? Onkeypress and onkeydown do not show first thing you paste or type because they happen before the text being added to text field.
Code:
<input type="text" id="targetTextField" onkeydown="CapturePastedString(this.id)" /> <script> function CapturePastedString(id){ var targetTextField=document.getElementById(id); // below I need to capture the pasted string like: var pasted_string= function(){.....} targetTextField.value=pasted_string; } </script>
View 4 Replies
View Related
Mar 21, 2007
I have a javascript/MSHTML editor loaded in an IFrame call "msEditor1". It gets composed after the document loads through document.write commands from a JS function. I'm trying to set the editor so whenever a key is typed I capture the key event from the editor and then go from there.
I have a handle to the editor using either one of these:
View 9 Replies
View Related
Nov 29, 2011
I am having a play around with javascript and the html5 canvas to evaluate the feasibility of using it for a few personal projects.I have tried using both setInterval or setTimeout to set up a very rough framerate for an animation.The framerate is fine when coupled with a simple delta timing to smooth out the changes however when running under a large load (large images) I cannot seem to capture keyboard events very easily.
If I wiggle around the mouse a bit, it makes the keyboard more responsive but is there any way to get the window to poll the inputs rather than wait for an event to fire?This is much worse on Linux but the issue is still around on Windows.
View 3 Replies
View Related
Feb 14, 2009
Can Javascript be used to detect a certain url and then "not" write some html according to that url and also detect something on the page and "then" display some html?.
Example: I'm working on a volusion site that uses asp. There's basically only one page that's changed dynamically. I would like to display some html when and only if the cart has any items in it. But also not to show up on the check-out pages.
The page dynamically displays "Your cart has 1 item in it..." when the visitors puts something in their cart.
So could javascript detect when this is displayed then write some html and then also detect if the url is showing the cart and then not show the html?
View 24 Replies
View Related
Jul 24, 2005
I wonder if I can associate some keys (e.g. 'Ctrl+T') to some function I create with JavaScript on my webpage.
View 2 Replies
View Related
Jul 28, 2005
I'm writing some stuff where I wish to allow the cursor keys to control
elements in a page. This has not been a problem except with Safari
which appears to duplicate the keydown and keyup events which are fired
when the cursor keys are pressed. I.e. pressing and releasing say, K,
results in one keydown event followed by one keyup event. Press any of
the cursor keys results in two keydown events followed by two keyup
events.....
View 3 Replies
View Related
Mar 25, 2007
Does anybody know why doesn't onkeypress catch up/down arrow keys
while it catches left/right arrows? My only supposition is that up/
down keys are used for moving between form elements, anyway does
anybody know any solution to this problem?
View 1 Replies
View Related
Jan 9, 2010
I'm trying to figure out how to select a value from a list that is filled dynamically using ajax auto suggest Take a look at the small code: when typing in a name by the keyboard this function is called:
[Code]...
View 6 Replies
View Related
Mar 5, 2011
I have a little problem that i hope can be solved. You start to type in an <input> field and a list of results show based on what you type, I have a list of Airports in MySQL that is check for LIKE of what is typed in and the matches show that can be selected. But you can only scroll with the mouse and not the arrow keys.
Does anyone know how I may allow arrow keys as well as the mouse to select their choice?
View 2 Replies
View Related
Sep 14, 2009
I want to block alt+f4 key using javascipt. Please give some example.
View 1 Replies
View Related
Jan 26, 2010
Firstly, apologies for my terrible JavaScript knowledge! I'm getting there! I have an array that is made up of the results of a few SQL queries. The queries return the record id and an integer. I need to sort the results of the queries by the integer. I am trying to store them in an array, using the record is as the key, then sorting the array. However, when I try to get the data out of the array, it has changed the key!
E.g.
Original results
[10605] = 141
[10744] = 116
[18835] = 166
[15304] = 166
[Code]...
View 13 Replies
View Related
Feb 24, 2010
Disable Arrow Keys I am creating an online flash gaming site, Aaron's Game Zone: [URL]Some of the games on it use the arrow keys, however IE also uses them to scroll the page. I am learning JavaScript and am trying to write some script to pervent the page scrolling up and down while playing a game.For example.Guardian Rock uses the arrow keys to slide around, at the same time the page scrolls.[URL]
Here is the script I've tried to write to pervent the scrolling:
<script type="text/javascript">
function KeyPressHappened(e){
if (!e) e=window.event;
[code]....
View 2 Replies
View Related
Mar 17, 2011
I was under the impression that I and object/associative array could have other objects as the keys for properties. That is, I should be able to set myObject[anotherObject] = 1. However, while this seems to work at first glance, any new object I set as a property key overwrites the first one.Here is the result of me testing in my Chrome console:
> var obj1 = new Object();
> var obj1.someProperty = "test"
"test"
[code]....
View 9 Replies
View Related
Oct 1, 2009
How to use the shortcut keys in jvascript? Any illustration with an example? Such as suppose on clicking the Ctrl+alt key, I want to display a prompt dialog box........How to do this?
View 3 Replies
View Related
Feb 4, 2010
I'm experiencing some problems with setting "onkeydown" dynamically.I want to pass some parameters to the function which recieves the event.So I did this:
mydiv.setAttribute('onkeydown','ShowInput(this,''+divID+'');
Only of course it doesn't work in IE.So I tried setting it the other way:
mydiv.onkeydown = ShowInput;
But that way I cannot pass parameters?
View 2 Replies
View Related