Code:
function addtag(tag,number,tag2) {
var txt = document.getElementById('message');
if(document.selection) {
txt.focus();
sel = document.selection.createRange();
if(number == 0) sel.text = tag;
if(number == 1) sel.text = '[' + tag + ']';
if(number == 2) sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
if(number == 3) sel.text = tag + sel.text + tag2;
} else if(txt.selectionStart || txt.selectionStart == '0') {
oldSelectionStart=txt.selectionStart;
oldSelectionEnd=txt.selectionEnd;
if(number == 0) txt.value = (txt.value).substring(0, txt.selectionStart) + tag + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 1) txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 2) txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 3) txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 0) txt.selectionStart=oldSelectionStart+tag.length;
if(number == 1) txt.selectionStart=oldSelectionStart+tag.length+2;
if(number == 2) txt.selectionStart=oldSelectionStart+tag.length*2+5+oldSelectionEnd-oldSelectionStart;
txt.selectionEnd=txt.selectionStart;
if(number == 3) txt.selectionStart=oldSelectionStart+tag.length*2+5+oldSelectionEnd-oldSelectionStart;
txt.selectionEnd=txt.selectionStart;
} else {
if(number == 0) txt.value = tag;
if(number == 1) txt.value = '[' + tag + ']';
if(number == 2) txt.value = '[' + tag + '][/' + tag + ']';
if(number == 3) txt.value = tag + tag2;
}
return;
}
function addtag(tag,number,tag2) {
var txt = document.getElementById('message');
if(document.selection) {
txt.focus();
sel = document.selection.createRange();
if(number == 0) sel.text = tag;
if(number == 1) sel.text = '[' + tag + ']';
if(number == 2) sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
if(number == 3) sel.text = tag + sel.text + tag2;
} else if(txt.selectionStart || txt.selectionStart == '0') {
oldSelectionStart=txt.selectionStart;
oldSelectionEnd=txt.selectionEnd;
if(number == 0) txt.value = (txt.value).substring(0, txt.selectionStart) + tag + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 1) txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 2) txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 3) txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
if(number == 0) txt.selectionStart=oldSelectionStart+tag.length;
if(number == 1) txt.selectionStart=oldSelectionStart+tag.length+2;
if(number == 2) txt.selectionStart=oldSelectionStart+tag.length*2+5+oldSelectionEnd-oldSelectionStart;
txt.selectionEnd=txt.selectionStart;
if(number == 3) txt.selectionStart=oldSelectionStart+tag.length*2+5+oldSelectionEnd-oldSelectionStart;
txt.selectionEnd=txt.selectionStart;
} else {
if(number == 0) txt.value = tag;
if(number == 1) txt.value = '[' + tag + ']';
if(number == 2) txt.value = '[' + tag + '][/' + tag + ']';
if(number == 3) txt.value = tag + tag2;
}
return;
}
Šta ovom js-u fali? Kada se to primeni na ovaj kod (html):
Code:
<form name="forma">
<textarea name="text" cols="33" rows="10" lang="hr"></textarea><br>
sqrt - <a class="small" href="javascript:addtag('Math.sqrt(',')')">Math.sqrt( )</a><br>
<form name="forma">
<textarea name="text" cols="33" rows="10" lang="hr"></textarea><br>
sqrt - <a class="small" href="javascript:addtag('Math.sqrt(',')')">Math.sqrt( )</a><br>
prijavljuje grešku ?
[Ovu poruku je menjao Milan_n _ dana 17.07.2013. u 19:40 GMT+1]