471,887 Members | 1,509 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

How can I position the cursor at a specific point from the end of a text area?

I have the following Javascript function on a page:

Expand|Select|Wrap|Line Numbers
  1. function makeBold(target) {
  2. document.getElementById(target).focus();
  3. document.getElementById(target).value=document.getElementById(target).value.concat('<b></b>');
  4. }
On the page is an image with this HTML:

[HTML]<a onclick="javascript: makeBold('description');"><img src="images/button_bold.gif" border="0"></a>[/HTML]

When I click on the button, the function makeBold() adds the HTML tags <b></b> to the end of a text area named "description". It also puts the cursor at the end of these tags. This is good, but what I really want to do is put the cursor between the beginning <b> tag and the end </b> tag. The idea is to make the text area resemble the fuctionality of Dreamweaver.

Is there any way I can set the position of the cursor between the tags? I think maybe some way to put the cursor at a specific distance from the end of the text area is the way to go, but I am not good enough at this.

Any help you can give would be appreciated! Thanks!
Nov 18 '07 #1
1 1428
16,027 Expert Mod 8TB
Introduction to Ranges should get you started.
Nov 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Steve | last post: by
1 post views Thread by Tantra Veda | last post: by
reply views Thread by Jed Ozone | last post: by
2 posts views Thread by Gene Hubert | last post: by
reply views Thread by Andy Wynn | last post: by
1 post views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.