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 4669
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |