473,503 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tab keycode

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
3 1971
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
26848
by: Matthias Knöchlein | last post by:
hi !! I have the following problem : Is there a function or a constant value to check if a keyCode is a key kile "Shift", "Alt" or "F1". I would like not to use this way : if( ...
6
3887
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
1
20741
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
6
14879
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
4
21223
by: Thomas Christensen | last post by:
I'm trying to figure out what key the user pressed using a Danish keyboard layout. charCodeAt returns the correct number, but event.keyCode returns a wrong number, when using one of the keys that...
3
26321
by: Pugi! | last post by:
I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using Javascript & DOM'. function aKeyWasPressed(e) { if (window.event) { var key = window.event.keyCode; } else { var key...
5
2932
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
4
1990
by: Nathan Sokalski | last post by:
I am writing a piece of code for an ASP.NET function that generates an onKeyPress JavaScript eventhandler that uses the event.keyCode / event.which properties. I have two situations that I would...
3
5135
by: Paul Gorodyansky | last post by:
Hi, I have function that works via onkeypressed - for example, what to catch when a user presses a punctuation symbol such as '.' So I check keyCode for that - works just fine in Opera 8,...
2
2631
dlite922
by: dlite922 | last post by:
got the following code that works great in IE, i have need an exception to these rules. Why to Tab? Users come from old Apps (data entry people) and want to use the enter key to move through...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.