Nasiel som tu niekde na tejto stranke celkom dobry script, rozsiril som si ho, len mam problem, ze by ho potrebujem vyuzivat vo viacerych textarea v zavislosti od toho kde mam kurzor, da sa to nejak spravit?
Ten kod je:
Kód:
<!DOCTYPE html>
<button type=button onclick="addtag('b')"><b>tučné</b></button>
<button type=button onclick="addtag('i')"><i>kurzíva</i></button>
<button type=button onclick="addtag('u')"><u>počiarknuté</u></button>
<button type=button onclick="addtag('s')"><s>prečiarknuté</s></button>
<button type=button onclick="addtag('cite', true)">„citácia“</button>
<button type=button onclick="addtag('code')"><code>strojopis</code></button>
<button type=button onclick="addtag('nobr')"><nobr>nezalamovať text</nobr></button>
<button type=button onclick="addtag('sup')"><sup>horný index</sup></button>
<button type=button onclick="addtag('sub')"><sub>dolný index</sub></button>
<button type=button onclick="addtag('small')"><small>zmenšené</small></button>
<button type=button onclick="addtag('big')"><big>zväčšené</big></button>
<BR>
<script>
function addtag(g, o)
{
var t = document.getElementsByTagName('textarea')[0];
if (typeof t.selectionStart == 'number')
{
var v = t.value,
s = t.selectionStart,
e = t.selectionEnd;
if (!o)
{
t.value = v.substring(0, s) + String.fromCharCode(60)+g+'>' + v.substring(s, e) + String.fromCharCode(60)+'/'+g+'>' + v.substring(e);
}
else if (g == 'img')
{
t.value = v.substring(0, s) + String.fromCharCode(60)+'img src="' + v.substring(s, e) + '">' + v.substring(e);
}
else if (g == 'cite')
{
t.value = v.substring(0, s) + '„' + v.substring(s, e) + '“' + v.substring(e);
}
else
{
return;
}
}
else if (document.selection)
{
t.focus();
s = document.selection.createRange();
if (s.parentElement() == t)
{
if (!o)
{
s.text = String.fromCharCode(60)+g+'>' + s.text + String.fromCharCode(60)+'/'+g+'>';
}
else if (g == 'img')
{
s.text = String.fromCharCode(60)+'img src="' + s.text + '">';
}
else if (g == 'cite')
{
s.text = '„' + s.text + '“';
}
else
{
return;
}
}
}
else
{
return;
}
}
</script>
<textarea cols="45" rows="2" name="PON_SO" /></textarea>
<textarea cols="45" rows="2" name="UTO_SO" /></textarea>
<textarea cols="45" rows="2" name="STV_SO" /></textarea>