html tag buttons

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

html tag buttons

Post by andylyon87 »

How do I go about creating the buttons on forms that allow the user to click them and insert html tags into the textarea box.

Say <B> </B>
or <BR>

like te ones on the forms for posting, I understand it is jscript if someone knows of somewhere there is a tutorial or a good description or someone can just describe it to me, I am having difficulty finding anything about it.

thanks
andylyon87 :)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You use a bit of javascript.

Code: Select all

function addTag(tag, field)&#123;
   window.document.<name of form>.field.value = window.document.<name of form>.field.value + tag
&#125;
And then have onClick in the button:

Code: Select all

<input type="button" value="Click Me" onClick="addTag('&#1111;b]', some_field)"
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

would this insert one tag per button say

button 1:<B>
button 2:</B>

or could you have

button 1: <B> +text+ </B>

and if so how would you do the latter
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

you can do it by using onDoubleclick() i think.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

to insert text around a selection you need to work with the selection objects.

http://www.quirksmode.org/js/selected.html
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

I cant get the first solution to work as i am unsure as to what to put in the field name.
Also i am unsure of how to use the solution provided by feyd to produce something to add tags I understand it gets selected text which could then have tags added to it but I am a rubbish jscrtipter and am more of a beginner in this so have no idea of how to go about this.
Post Reply