Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Add Text To Textarea, I suppose it uses DOM and JavaScript??
FirefoxRocks
post Mar 4 2007, 05:25 PM
Post #1


Super Member
Group Icon

Group: [HOSTED]
Posts: 693
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



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
<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.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Mar 5 2007, 06:19 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 760
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(FirefoxRocks @ Mar 4 2007, 12:25 PM) *
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
<html>
<head>
&lt;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
<html>
<head>
&lt;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 wink.gif

Best regards,
Go to the top of the page
 
+Quote Post
iGuest
post Oct 31 2007, 05:14 AM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



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
Go to the top of the page
 
+Quote Post
iGuest
post Mar 4 2008, 01:29 PM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



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
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Mar 5 2008, 04:22 AM
Post #5


Premium Member
Group Icon

Group: [HOSTED]
Posts: 391
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322



QUOTE(FeedBacker @ Mar 4 2008, 06:59 PM) *
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.

CODE
document.getElementById('txt1').value = myVar;
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Mar 5 2008, 04:56 AM
Post #6


Super Member
Group Icon

Group: [HOSTED]
Posts: 693
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



Is there a way to control where the cursor is by means of moving it through a number of characters of the text inserted?
Go to the top of the page
 
+Quote Post
mastercomputers
post Mar 5 2008, 11:47 AM
Post #7


BUG.SWAT.PATROL
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



QUOTE(FirefoxRocks @ Mar 5 2008, 05:56 PM) *
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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Getting Screen Resolution using Javascript.(8)
  2. How To Create A Popup Window With Javascript?(19)
  3. javascript vs java(12)
  4. Javascript: Disable Mouse Right-click In Browser(16)
  5. Best Way To Learn Javascript(9)
  6. Javascript: Text To Texbox And Back To Text(2)
  7. Dynamicdrive: Good Site For JavaScript Codes(5)
  8. Status Bar Effect(5)
  9. Javascript: Simple Slidedown Menu(2)
  10. JavaScript: Simple Dropdown Menu(1)
  11. Javascript: Browser Detection Script(0)
  12. JavaScript: Hide And Show Any Element With CSS(5)
  13. Ever Needs To Find Out A Table Height Or With With JavaScript(2)
  14. Create And Import JavaScript Modules For A Large Script(2)
  15. Vertical Marquee Using JavaScript(0)
  1. JavaScript Frames & Querystring(4)
  2. Highlight The Active Text Input Fields.(1)
  3. JavaScript Off Redirect Script(2)
  4. I Need Help With Javascript.(7)
  5. Problems With Dynamically Loading Javascript(2)
  6. Javascript Question(4)
  7. Javascript: How Do I Create Embedded Pop-up Windows?(7)
  8. Vertical Text(1)
  9. Problem With Javascript Alert();(9)
  10. Include Function For Javascript(7)
  11. Fun With Javascript And Forms(2)
  12. Javascript Help Needed : Alert(z) Works Fine But Document.write Not(2)
  13. Javascript Changes Aren't Working.(6)


 



- Lo-Fi Version Time is now: 7th October 2008 - 06:46 PM