TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Add to text field when clicked? (http://www.talkphp.com/absolute-beginners/5822-add-text-field-when-clicked.html)

Tim Dobson 03-22-2011 08:12 PM

Add to text field when clicked?
 
1 button and 1 text area

PHP Code:

<textarea name="addpaste" cols="100" rows="25" id="addpaste"></textarea>
<
br />
<
input type="button" value="Bold" name="addbld" /> 

Now what i need to do is when the the button is pressed i need [bld] to be inserted in to the textarea. Any suggestions? thanks.

tony 03-23-2011 12:06 AM

It seems that you want that to be accomplished in the client side, using javascript. I know how to insert text, but I am not sure how to insert it where the cursor is at.

If you just want to insert it. here is some sample code :
javascript Code:
//add an id to the textarea with same as name also to button
document.getElementById('addbld').onClick(function(){
  var txtArea = document.getElementById('addpaste');
  txtArea.value = textArea.value + '[bld]';
});

I am not an expert on javascript though. It has been a while.


All times are GMT. The time now is 05:13 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0