Jump to content

how to surround a text by tag using a button ?


lofaifa

Recommended Posts

thank you != worked

 

i found a function :

 

function applyTag(obj,tag)
{wrapText(obj, '['+tag+']', '[/'+tag+']');};

function wrapText(obj, beginTag, endTag)
{
if(typeof obj.selectionStart == 'number')
{
	// Mozilla, Opera, and other browsers
	var start = obj.selectionStart;
	var end   = obj.selectionEnd;
	obj.value = obj.value.substring(0, start) + beginTag + obj.value.substring(start, end) + endTag + obj.value.substring(end, obj.value.length);
}
else if(document.selection)
{
	// Internet Explorer
	// make sure it's the textarea's selection
	obj.focus();
	var range = document.selection.createRange();
	if(range.parentElement() != obj) return false;

    if(typeof range.text == 'string')
        document.selection.createRange().text = beginTag + range.text + endTag;
}
else
	obj.value += text;
};

 

 

and this in You page :

 

<input type="button" value="bold" onclick="applyTag(document.getElementById('question_text'),'strong')" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.