Visit Jeremy's Blog.
Go Back > Forums > > LQ Suggestions & Feedback
User Name
LQ Suggestions & Feedback Do you have a suggestion for this site or an idea that will make the site better? This forum is for you.
PLEASE READ THIS FORUM - Information and status updates will also be posted here.


  Search this Thread
Old 02-14-2008, 11:07 PM   #1
Registered: Aug 2005
Posts: 298

Rep: Reputation: 30
tab button in textbox

An anoying thing is when pressing tab the textbox looses focus. It would be nice if it inserts a tab.

What I do is associate the keypress of a textbox with a function say txtkeypress().

// This code I got somewhere along time ago. 
function insertAtCursor(myField, myValue) {
    //IE support
    var xs, ys;
    // Save scrolling positions
    xs = myField.scrollLeft;
    ys = myField.scrollTop;
    if (document.selection) {
        sel = document.selection.createRange();
        sel.text = myValue;
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == "0") {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)
        + myValue
        + myField.value.substring(endPos, myField.value.length);
        myField.selectionStart = startPos +1 ;
        myField.selectionEnd = startPos + 1;
    } else {
        myField.value += myValue;
    myField.scrollTop = ys;
    myField.scrollLeft = xs;

function txtkeypress(txt, e) {
    if(e.keyCode == 9){
        insertAtCursor(txt, "\t");
        return false;
And tab inserts instead of loosing focus. Might not work for all browsers but atleast its a start.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change TextBox Color rn5a Linux - Newbie 3 09-23-2007 06:14 PM
insert textbox in openoffice Four Linux - Newbie 4 03-23-2006 10:07 PM
FC 4. Modify ALT+TAB behaviour to CTRL+TAB xtracto Linux - Software 1 09-22-2005 02:06 PM
wxPython textbox command line help arpanet1969 Programming 5 09-13-2005 05:38 PM
I want the TAB button to work like WinDoze mr.flywheel Mandriva 5 12-20-2004 04:30 PM > Forums > > LQ Suggestions & Feedback

All times are GMT -5. The time now is 08:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration