Jump to content
xisto Community
FirefoxRocks

Add Text To Textarea I suppose it uses DOM and JavaScript??

Recommended Posts

I am working on a web "application" thing that allows you to click a button to add text to a textarea.Similar to this forum when you click the BOLD button and it puts in {b}{/b} with the square brackets. I want a similar function like that. Also, I want it to add wherever the cursor is, not at the end. And after adding the thing, the cursor should be in between the tag or whatever that was added.All the extra stuff are extra priorities. For now I would like to get something that inserts text on click.The thing I came up with is:

<html><head><script type="text/javascript">function write() {document.form.textarea.value = "This is the stuff that goes into the textarea";}</script></head><body><textarea id="txt1">Hello world....This is a text area</textarea></body></html>

I know that isn't right, so I need more help on this.

Share this post


Link to post
Share on other sites

I am working on a web "application" thing that allows you to click a button to add text to a textarea.Similar to this forum when you click the BOLD button and it puts in {b}{/b} with the square brackets. I want a similar function like that. Also, I want it to add wherever the cursor is, not at the end. And after adding the thing, the cursor should be in between the tag or whatever that was added.

All the extra stuff are extra priorities. For now I would like to get something that inserts text on click.
The thing I came up with is:

<html>
<head>
<script type="text/javascript">
function write() {document.form.textarea.value = "This is the stuff that goes into the textarea";}
</script>
</head>
<body><textarea id="txt1">Hello world....This is a text area</textarea></body>
</html>



I know that isn't right, so I need more help on this.

I view this kind of script in many sites and it is not difficult to code, so try this:
<html>
<head>
<script type="text/javascript">
function mywrite() {
  form.txt1.focus();
  form.txt1.value = "This is the stuff that goes into the textarea";
}
</script>
</head>
<body>
<form name="it">
<input onclick="mywrite()" type="button" value="add text" title="add text to text area">
<textarea id="txt1" name="txt1"></textarea>
</form>
</body>
</html>


As you can see, it is a basic and very simple version, for a start is enough ;)

Best regards,

Share this post


Link to post
Share on other sites

I am working on tiff image, I want to draw a rectangle on tiff image to highlight the some part of image. I have loaded tiff image in the browser using embed tag and used tiff plug ins. can you please help me? how to draw the rectangle with transparent color to highlight the part of image? thanks-Amol

Share this post


Link to post
Share on other sites

text editor

Add Text To Textarea

 

How can I write content of a variable in javascriptt that I have fetched from database through php

 

-reply by rajesh

Share this post


Link to post
Share on other sites

text editor

 

Add Text To Textarea

How can I write content of a variable in javascriptt that I have fetched from database through php

 

-reply by rajesh


Thats not difficult at all. Just substitute the variable for the message. For example, if myVar is your variable containing the database result and you want it to be displayed in the textarea with the ID txt1.

 

document.getElementById('txt1').value = myVar;

Share this post


Link to post
Share on other sites

Is there a way to control where the cursor is by means of moving it through a number of characters of the text inserted?

There are ways, though I don't have time to write it up. You'll need to investigate createTextRange and SelectionStart, you'll need to use both to make it more compatible, so test for each object before using it.

Cheers,

MC

Share this post


Link to post
Share on other sites
The same of the textarea that convert...Add Text To Textarea

Hi ! I want the same of this text area that convert to Rich-text. It is possible ? I'm not very good in java script. Thanks for your help !

-reply by Patfreeze

Share this post


Link to post
Share on other sites

I personally suggest just to learn and use jquery or some other javascript framework which makes things much much easier.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.