Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change format text selection in div

1 view
Skip to first unread message

Angel GX

unread,
Jun 28, 2008, 7:18:58 PM6/28/08
to
hi ;)

You forgive my English;)
I speak Spanish.

I want to put it into the selected text in bold tag DIV.
Most do not know how to write the script
Already tried unsuccessfully
------------------------------------------------

<style type="text/css">
.highlighted {
background-color: yellow;
color: darkgreen;
font-weight: bold;
}

</style>

<script>

function decodeIt(textfield) {
strSelection = ""
if (document.selection) {
strSelection = document.selection.createRange().text;
strSelection = strSelection.replace(new RegExp("<","g"), "&lt;");
strSelection = strSelection.replace(new RegExp(">","g"), "&gt;");
document.selection.createRange().text = strSelection;
}
//MOZILLA/NETSCAPE support
else if (textfield.selectionStart || textfield.selectionStart == '0')
{
textfield.focus();
var startPos = textfield.selectionStart;
var endPos = textfield.selectionEnd;
strSelection = textfield.value.substring(startPos, endPos)
alert('hola '+strSelection)
strSelection = strSelection.replace(new RegExp("<","g"), "&lt;");
strSelection = strSelection.replace(new RegExp(">","g"), "&gt;");
textfield.value = textfield.value.substring(0, startPos) +
strSelection + textfield.value.substring(endPos,
textfield.value.length);
}
}

function m(){
element=document.getElementById('n');
sel = window.getSelection();
selectionStart= 2
selectionEnd= 4


if (typeof document.createRange != 'undefined') {
var range = document.createRange();
if (element.firstChild) {
range.setStart(element.firstChild, startOffset);
range.setEnd(element.firstChild, endOffset);
var span = document.createElement('span');
span.className = 'highlighted';
range.surroundContents(span);

}
}


}
</script>
<input type="button" onclick="decodeIt(document.y.i)" value="Decode
it">
<input type="button" onclick="m()" value="Decode it div">
<form name=y id=y>
<textarea id=i name=i >asoa dald aldada</textarea>
</form>
<div id=n name=n>strSelection asas</div>
--------------------------------------------------------------------------

Thank you for your time ;)

angel matias orozco

0 new messages