Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Ubacivanje taga u selektovan deo teksta pomoć ?

[es] :: Javascript i AJAX :: Ubacivanje taga u selektovan deo teksta pomoć ?

[ Pregleda: 2046 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Milan_n _
Milan Ivanovic
Smarač

Član broj: 291415
Poruke: 83
*.dynamic.isp.telekom.rs.



+158 Profil

icon Ubacivanje taga u selektovan deo teksta pomoć ?17.07.2013. u 18:25 - pre 130 meseci
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;
}


Š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>


prijavljuje grešku ?


[Ovu poruku je menjao Milan_n _ dana 17.07.2013. u 19:40 GMT+1]
 
Odgovor na temu

ivan.a
PHP developer

Član broj: 83976
Poruke: 403
89.216.28.*



+44 Profil

icon Re: Ubacivanje taga u selektovan deo teksta pomoć ?18.07.2013. u 06:43 - pre 130 meseci
Nigde nije određen element (id) gde se primenjuje ovaj kod. Ne znam kako si to zamislio...da zakpriš preko tuđeg koda? :)

Code:
<form name="forma">
<textarea name="text" cols="33" rows="10" lang="hr" id="message"></textarea><br />

code - <a class="small" href="javascript:addtag('code','3','/code')">Code</a><br />
</form>

I hope I didn't brain my damage - Homer
if (wife.position == kitchen) {return sandwich};
 
Odgovor na temu

[es] :: Javascript i AJAX :: Ubacivanje taga u selektovan deo teksta pomoć ?

[ Pregleda: 2046 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.