hi i recently used a virtual keyboard from www.codeproject.com/jscript/jvk.asp.
However this part of the code - function keyb_callback(ch)
-
{
-
var text = document.getElementById("textfield"), val = text.value;
-
-
switch(ch)
-
{
-
case "BackSpace":
-
if(val.length)
-
{
-
var span = null;
-
-
if(document.selection)
-
span = document.selection.createRange().duplicate();
-
-
if(span && span.text.length > 0)
-
{
-
span.text = "";
-
getCaretPositions(text);
-
}
-
else
-
deleteAtCaret(text);
-
}
-
-
break;
-
-
default:
-
insertAtCaret(text, (ch == "Enter" ? (window.opera ? '\r\n' : '\n') : ch));
-
}
-
}
-
-
// This function retrieves the position (in chars, relative to
-
// the start of the text) of the edit cursor (caret), or, if
-
// text is selected in the TEXTAREA, the start and end positions
-
// of the selection.
-
//
-
function getCaretPositions(ctrl)
-
{
-
var CaretPosS = -1, CaretPosE = 0;
-
ctrl.focus();
-
-
// Mozilla way:
-
if(ctrl.selectionStart || (ctrl.selectionStart == '0'))
-
{
-
CaretPosS = ctrl.selectionStart;
-
CaretPosE = ctrl.selectionEnd;
-
-
insertionS = CaretPosS == -1 ? CaretPosE : CaretPosS;
-
insertionE = CaretPosE;
-
}
-
// IE way:
-
else if(document.selection && ctrl.createTextRange)
-
{
-
// The current selection:
-
var range;
-
if(ctrl.tagName.toLowerCase() == "input")
-
{
-
range = ctrl.createTextRange();
-
}
-
else if(ctrl.tagName.toLowerCase() == "textarea")
-
{
-
range = document.selection.createRange();
-
}
-
-
// We'll use this as a 'dummy':
-
var stored_range = range.duplicate();
-
-
// Select all text:
-
stored_range.moveToElementText(ctrl);
-
-
// Now move 'dummy' end point to end point of original range:
-
stored_range.setEndPoint('EndToEnd', range);
-
-
// Now we can calculate start and end points:
-
insertionS = stored_range.text.length - range.text.length;
-
insertionE = insertionS + range.text.length;
-
}
-
}
-
-
function setRange(ctrl, start, end)
-
{
-
if(ctrl.setSelectionRange) // Standard way (Mozilla, Opera, ...)
-
{
-
ctrl.setSelectionRange(start, end);
-
}
-
else // MS IE
-
{
-
ctrl.focus();
-
-
var range;
-
-
try
-
{
-
range = ctrl.createTextRange();
-
}
-
catch(e)
-
{
-
try
-
{
-
range = document.body.createTextRange();
-
range.moveToElementText(ctrl);
-
}
-
catch(e)
-
{
-
range = null;
-
}
-
}
-
-
if(!range) return;
-
-
range.collapse(true);
-
range.moveStart("character", start);
-
range.moveEnd("character", end - start);
-
range.select();
-
}
-
-
insertionS = start;
-
insertionE = end;
-
}
-
-
function deleteSelection(ctrl)
-
{
-
if(insertionS == insertionE) return;
-
-
var tmp = (document.selection && !window.opera) ? ctrl.value.replace(/\r/g,"") : ctrl.value;
-
ctrl.value = tmp.substring(0, insertionS) + tmp.substring(insertionE, tmp.length);
-
-
setRange(ctrl, insertionS, insertionS);
-
}
-
-
function deleteAtCaret(ctrl)
-
{
-
// if(insertionE < insertionS) insertionE = insertionS;
-
if(insertionS != insertionE)
-
{
-
deleteSelection(ctrl);
-
return;
-
}
-
-
if(insertionS == insertionE)
-
insertionS = insertionS - 1;
-
-
var tmp = (document.selection && !window.opera) ? ctrl.value.replace(/\r/g,"") : ctrl.value;
-
ctrl.value = tmp.substring(0, insertionS) + tmp.substring(insertionE, tmp.length);
-
-
setRange(ctrl, insertionS, insertionS);
-
}
-
-
// This function inserts text at the caret position:
-
//
-
function insertAtCaret(ctrl, val)
-
{
-
if(insertionS != insertionE) deleteSelection(ctrl);
-
-
if(document.createEvent && !window.opera)
-
{
-
var e = document.createEvent("KeyboardEvent");
-
-
if(e.initKeyEvent)
-
{
-
e.initKeyEvent("keypress", // in DOMString typeArg,
-
false, // in boolean canBubbleArg,
-
true, // in boolean cancelableArg,
-
null, // in nsIDOMAbstractView viewArg, specifies UIEvent.view. This value may be null;
-
false, // in boolean ctrlKeyArg,
-
false, // in boolean altKeyArg,
-
false, // in boolean shiftKeyArg,
-
false, // in boolean metaKeyArg,
-
null, // key code;
-
val.charCodeAt(0));// char code.
-
-
ctrl.dispatchEvent(e);
-
}
-
}
-
else
-
{
-
var tmp = (document.selection && !window.opera) ? ctrl.value.replace(/\r/g,"") : ctrl.value;
-
ctrl.value = tmp.substring(0, insertionS) + val + tmp.substring(insertionS, tmp.length);
-
}
-
-
setRange(ctrl, insertionS + val.length, insertionS + val.length);
-
}
work well with textarea on IE but many errors arise when used on a textbox
Some errors include
The words are appended to the front of the orginals word
Insertion/delete in the middle does not work
I am on a tight schedule so i hope u guys can help me solve my problem asap.
Thanks
1 4701
Hi,
the script you're talking about was updated: http://www.codeproject.com/jscript/jvk.asp
Advanced callback function (that you quote) was updated too; it doesn't have any problems with either TEXTAREA and INPUT of type="text".
Best regards.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: visual basic dummy |
last post by:
I have taken a course at the local college. It is called Advanced
Languages and this course will cover C++, Perl and Javascript. I must
pass this course. In January/Feb we covered a 1000+page textbook. It
has been more than 3 years since I took C language. I have already
written my final exam for C++ and just barely passed with a 65%. I
have a project that is due on 25 March. I really need someone to sit
with me to do this project. I need...
|
by: Steven Malcolm |
last post by:
Hi
I am trying to build an application at work which will use a virtual
keyboard on a touch screen.
I have searched the archives and found references but nothing to download.
If anyone has any examples of a virtual keyboard that I could use that would
be great.
|
by: Jo Segers |
last post by:
Hi,
How can I restrict the keyboard input in a textBox to 0..9? In the
keydown event KeyValue is get only. Where can I alter the keyboard input?
Mvg,
|
by: Roshawn Dawson |
last post by:
Hi,
Could someone tell how to force a mouse event using either jscript or
javascript? I simply want to allow users to scroll the page after
postbacks using the scroll button on either a mouse or the keyboard
without them having to click the page first.
Thx,
Roshawn
|
by: Benton |
last post by:
Hi there,
I have a text box which will receive its value from a pop-up date picker.
The user should not be able to edit this field with the keyboard or mouse.
I am using ASP.NET. If I set the readonly property of the textbox to true,
it won't let the user change it and it can receive its value from the pop-op
calendar, just what I need. Problem is, after a postback, value is lost.
So I think Javascript may come to the rescue here. Is...
| |
by: dieselmachine |
last post by:
Hey, I've been searching for info on this for days now, but to no
avail. I'm starting to think it's impossible, but anyway!
I've coded a little virtual keyboard, which has two octaves worth of
keys on it, and when the keyboard image is clicked, it uses the
coordinates to determine what key was pressed, then some stuff happens
that we needn't worry about. I want to make the keys play the
appropriate note when clicked, and I can't figure...
|
by: Sirisha |
last post by:
I have one textbox for enter telephone numbers.
i want that text box can accepts only 0 to 9 digits and one sapcace,
-,special characters.
I want Javascript script validation for that text box.
|
by: =?Utf-8?B?Sm9obiBBdXN0aW4=?= |
last post by:
The HP t5520 Windows CE based thin client comes with a browser called
'Internet Explorer' - iehp.exe. It appears to have Java script
(Request.Browser.JavaScript = True). I want to use this browser in
conjunction with a 'keyboard wedge' magnetic card reader (and no keyboard) to
record the arrival of staff and to display information about the employees
jobs for the day. The webform has a textbox that must maintain focus so that
when a...
|
by: manusiatidakbiasa |
last post by:
Hi,
I am new in javascript,
I am currently building a simple website,
and I like to make a keyboard shortcut
so when someone press ctrl-1,
it will give keyboard focus to a textbox
can anyone help me?
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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...
| |