LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > LinuxQuestions.org > LQ Suggestions & Feedback
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-14-2008, 11:07 PM   #1
Four
Member
 
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().

Code:
// 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) {
        myField.focus();
        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;
    }
    txtChange(txt);
}
And tab inserts instead of loosing focus. Might not work for all browsers but atleast its a start.

Thanks
 
  


Reply


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


All times are GMT -5. The time now is 01:30 PM.

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