---
title: "Tabb i <textarea>"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/58165-tabb-i-textarea"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "Marcus"
published: "2002-11-05T20:32:29.000Z"
updated: "2003-06-10T14:42:53.000Z"
replies: 4
views: 277
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/58165-tabb-i-textarea"
---

# Tabb i <textarea>

## #1 — Marcus, 2002-11-05T20:32Z

Hej

Någon som vet hur man gör så att tabbtangenten betyder tabb i en \<textarea\>? Jag vill alltså INTE hoppa till nästa objekt utan skapa en tabb. 

Tack på förhand

Permalänk: https://www.webforum.nu/p/58165

## #2 — icaaq, 2002-11-05T20:48Z

Jag vet inte om det går ...inte med HTML iaf.
Man skulle ju kunna använda **OnKeyUp** i JavaScript.....kanske ;)

mvh icaaq

Permalänk: https://www.webforum.nu/p/845418

## #3 — Marcus, 2002-11-05T20:50Z

Jag hittade följande funktioner som hjälpte bra...

```php
function CheckTab(el) {
	  if ((document.all) && (9==event.keyCode) && (event.ctrlKey)) {
		el.selection=document.selection.createRange(); 
		setTimeout("ProcessTab('" + el.id + "')",0)
	  }
	}

	function ProcessTab(id) {
	  document.all[id].selection.text=String.fromCharCode(9)
	  document.all[id].focus()
	}
```

Permalänk: https://www.webforum.nu/p/845423

## #4 — icaaq, 2002-11-05T21:04Z

ok.....Jag hittade en iaf längre version av denna .....har inte testat den men ....här kommer den iaf

```
[red]
<SCRIPT>
/* Copyright 2000 SiteExperts.com/ InsideDHTML.com, LLC
This code can be reusedas long as the above copyright notice
is not removed */

function CheckTab(el) {
// Run only in IE
// and if tab key is pressed
// and if the control key is pressed
if ((document.all) && (9==event.keyCode)) {
// Cache the selection
if (event.shiftKey) {
el.selection=document.selection.createRange(); 
setTimeout("ProcessTab('" + el.id + "',true)",0)
} else
{
el.selection=document.selection.createRange(); 
setTimeout("ProcessTab('" + el.id + "',false)",0)
}
}
}

function ProcessTab(id,shiftVal) {

if (shiftVal==false) { 
// tab only

// Insert tab character in place of cached selection
if (document.all[id].selection.text.length!=0) {
// more than one char selected
xSelection=document.all[id].selection.text
xSelection=String.fromCharCode(9)+xSelection

for (var x=0;x<xSelection.length;x++) {
if ((xSelection.charCodeAt(x)==10) && (xSelection.charCodeAt(x-1)==13)) {
// theres a 13 and 10 charcode in succession = newline
xSelection=xSelection.substring(0,x+1)+String.fromCharCode(9)+xSelection.substring(x+1,xSelection.length)
} // if charcodeat
} // for
document.all[id].selection.text=xSelection
} 
else {
document.all[id].selection.text=String.fromCharCode(9)
}

}
else { 
// shift and tab

// Remove tab character in place of cached selection
if (document.all[id].selection.text.length!=0) {
// more than one char selected
xSelection=document.all[id].selection.text
if (xSelection.charCodeAt(0)==9)
xSelection=xSelection.substring(1,xSelection.length)

for (var x=0;x<xSelection.length;x++) {
if ((xSelection.charCodeAt(x)==9) && (xSelection.charCodeAt(x-1)==10) && (xSelection.charCodeAt(x-2)==13)) {
// theres a 13,10 and 9(tab) charcode in succession = newline with tab
xSelection=xSelection.substring(0,x)+xSelection.substring(x+1,xSelection.length)
} // if charcodeat
} // for
document.all[id].selection.text=xSelection
} 
else {
alert ("Please select text when using Shift+Tab")
}

}

// Set the focus
document.all[id].focus()
}
</SCRIPT>

[/red]
```

mvh icaaq

Permalänk: https://www.webforum.nu/p/845441

## #5 — skyman, 2003-06-10T14:42Z

Vad är argumentet **el**???

Permalänk: https://www.webforum.nu/p/1080363

---

Tråden på webben: https://www.webforum.nu/amne/javascript/58165-tabb-i-textarea
