Forum Moderators: coopster

Message Too Old, No Replies

Adding text to textarea with a button

         

havoc

5:41 am on Feb 25, 2004 (gmt 0)

10+ Year Member



A while ago i posted a note on here asking how i could do this. I got a couple of replies but none of them helped . I think i worded the question wrong

What i want to do is this

i have a text area

¦------------------------¦
¦
¦
¦
¦------------------------¦
¦BOLD¦

When i pres bold it adds text to the text area (message)
as this

¦------------------------¦
¦ <b> </b>
¦
¦
¦------------------------¦
¦BOLD¦

Any ideas?!
Thanks guys

coolo

6:14 am on Feb 25, 2004 (gmt 0)

10+ Year Member



does it matter if the page reloads, or do you want it to happen automatically, without reloading the page?

havoc

7:25 am on Feb 25, 2004 (gmt 0)

10+ Year Member



yeh without a reload would be good ... i see it all the time on forum software so there has to be a way!

mykel79

9:38 am on Feb 25, 2004 (gmt 0)

10+ Year Member



I think it would be best to use Javascript like this:

<form>
<TEXTAREA NAME="textarea1" ROWS=10 COLS=10 WRAP=virtual>
</TEXTAREA><BR>
<INPUT TYPE="button" NAME="insert" VALUE="BOLD" onClick="this.form.textarea1.value='<b></b>';">
</FORM>

coopster

12:42 pm on Feb 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mykel79 is right, if you want to do this without a reload, you are talking about a client-side solution, such as javascript. Also, if you want the bold text to actually be displayed as bold text, you will need to write the textarea's value and have it parsed as HTML.

You mentioned that you posted on this topice before...did you have a look at the solution mentioned [webmasterworld.com]?

havoc

2:01 am on Feb 26, 2004 (gmt 0)

10+ Year Member



unfortunatly it clears everything you write in the box when you click it. is there a way to append it to what you have already written?

havoc

3:09 am on Feb 26, 2004 (gmt 0)

10+ Year Member



Coopster yes i did ... but that not what im after . i just want to add tags and when its posted it parsed automatically . I can do that i just need to know how to add the tags via a button to the text area ..

the solution above works but it erases everything

webadept

3:52 am on Feb 26, 2004 (gmt 0)

10+ Year Member



Yep, there is a way to do that, and phpBB does it very well.. I just poped into my version to see what the code was, thinking i would do a bit of cut and paste for you, but the length of it is ... well.. daunting to say the least. I can't let you into my phpBB, because it is a secret, but you can go to phpBB's website, and take a look at it there, and do the cut and past yourself.

That's the best text box editor on a webpage I've ever seen, so it might be good to take a look at what they are doing anyway.

mykel79

11:59 am on Feb 27, 2004 (gmt 0)

10+ Year Member



If you want to append some text to the textarea, do it like this:

<form>
<TEXTAREA NAME="textarea1" ROWS=10 COLS=10 WRAP=virtual>
</TEXTAREA><BR>
<INPUT TYPE="button" NAME="insert" VALUE="BOLD" onClick="this.form.textarea1.value=this.form.textarea1.value.concat('<b></b>');">
</FORM>

If you would like to put the <b> </b> around something highlighted in the textarea, that would be a totally different ballgame (more complicated)