webForumDet fria alternativet

Tabb i <textarea>

4 svar · 277 visningar · startad av Marcus

MarcusMedlem sedan juli 2000470 inlägg
#1

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

icaaqMedlem sedan okt. 20004 910 inlägg
#2

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

mvh icaaq

MarcusMedlem sedan juli 2000470 inlägg
#3

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

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()
	}
icaaqMedlem sedan okt. 20004 910 inlägg
#4

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

skymanMedlem sedan juli 20011 347 inlägg
#5

Vad är argumentet el???

Genererad på 380 ms · cache AV · v20260730165559-full.f96bc7eb