Ciao Gluck, grazie mille per la risposta e ho provato a metterlo in atto così:
codice:
function getSelText()
{
txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
else return;
return txt
}
function add_g() {
if (txt == '') {
text = prompt("Inserisci la parola o frase che desideri in grassetto...");
document.form_note.note.value = document.form_note.note.value + ""+ text +"";
document.form_note.note.focus();
} else {
document.form_note.note.value = document.form_note.note.value + ""+ txt +"";
document.form_note.note.focus();
}
}
codice:
<textarea onSelect="getSelText()" maxlength="1000"></textarea>
Ma effettivamente non va o.o In pratica:
Ho una textarea, seleziono qualcosa e clicco su un tasto che mi attiva la funziona add_g() [bold per intenderci]. La funzione verifica l'esistenza del testo selezionato e, se non esiste, mi apre un prompt, mentre se esiste mi aggiunge "" e "" con il testo selezionato in mezzo... (txt). Dove sbaglio?