By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

Tab keycode

P: n/a
Hi,
I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
when a 'tab' key is pressed. I have this code, which does not work,
can anyone explain me about this.

<html>
<head>
<script>
function chk(e){
if (e.keyCode==9){
c = document.getElementById('code');
d = c.value ;
d = d + "\t";
// d = d+" " ;
c.innerHTML = d ;
//alert (d);
}
}
</script>
</head>

<body>
<textarea id="code" onkeydown="chk(event)" rows=20 cols=60></textarea>
</body>
</html>
Jul 14 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
pra__ schreef:
I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
when a 'tab' key is pressed. I have this code, which does not work,
can anyone explain me about this.
Google for element.createTextRange

JW
Jul 15 '08 #2

P: n/a
pra__ wrote:
I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
when a 'tab' key is pressed. I have this code, which does not work,
"Does not work" is a useless error description.
can anyone explain me about this.

<html>
<head>
<script>
Your markup is not Valid to begin with.

<http://validator.w3.org/>
function chk(e){
if (e.keyCode==9){
c = document.getElementById('code');
d = c.value ;
d = d + "\t";
// d = d+" " ;
c.innerHTML = d ;
Appending the Tab character to the content of a `textarea' element will add
whitespace that is always interpreted as a single space in HTML. You should
modify the value of the `value' property instead:

c.value += "\t";

However, the Tab character is not uniformly rendered. If you want to put in
4 spaces, you should do exactly that:

c.value += " ";

And if it is your intention to insert 4 spaces at the caret position
instead, you should use your favorite search engine to look up the
corresponding FAQ entry. The suggested createTextRange() method will
only help with MSHTML, and the FAQ entry also is more verbose.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jul 15 '08 #3

P: n/a
On Jul 16, 12:32*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
pra__ wrote:
I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
when a 'tab' key is pressed. I have this code, which does not work,

"Does not work" is a useless error description.
can anyone explain me about this.
<html>
<head>
<script>

Your markup is not Valid to begin with.

<http://validator.w3.org/>
function chk(e){
* if (e.keyCode==9){
* * * c = document.getElementById('code');
* * * d = c.value ;
* * * d = d + "\t";
* * * *// d = d+" * *" ;
* * * c.innerHTML = d ;

Appending the Tab character to the content of a `textarea' element will add
whitespace that is always interpreted as a single space in HTML. *You should
modify the value of the `value' property instead:

* c.value += "\t";

However, the Tab character is not uniformly rendered. *If you want to put in
4 spaces, you should do exactly that:

* c.value += " * *";

And if it is your intention to insert 4 spaces at the caret position
instead, you should use your favorite search engine to look up the
corresponding FAQ entry. *The suggested createTextRange() method will
only help with MSHTML, and the FAQ entry also is more verbose.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
* * navigator.userAgent.indexOf('MSIE 5') != -1
* * && navigator.userAgent.indexOf('Mac') != -1
) *// Plone, register_function.js:16
Got it, Thanks :)
Jul 16 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.