Originariamente inviato da usecram
Salve raga,
sto realizzando un guestbook in php, ma non conoscendo per il momento Javascript (c'è l'ho sulla lista delle cose da fare), non saprei proprio come realizzare una funzione che mi permetta di utilizzare gli smilies così come in questo forum.
Non dovrebbe essere troppo complicato, non è che qualcuno potrebbe postarmi un po' di codice utile.
Ho già cercato ma non ho trovato tutto, solo alcuni spunti.
A buon rendere.
nella head:

codice:
<script language="JavaScript" type="text/JavaScript">

function Smile(textEl,insert){
	if (textEl.createTextRange && textEl.caretPos) {
		// MSIE
		var caretPos = textEl.caretPos;
		caretPos.text =	caretPos.text.charAt(caretPos.textEl.length - 1) == ' ' ? textEl + ' ' : textEl;
	} else if(textEl.selectionStart && textEl.setSelectionRange) {
		// Mozilla 1.3+
		var val = textEl.value;
		var cpos = textEl.selectionStart;
		var fpos = cpos + textEl.length;

		var before = val.substr(0,cpos);
		var after = val.substr(cpos, val.length);
		var aspace = after.charAt(0) == ' ' ? "" : " ";
		var bspace = before.charAt(before.length) == ' ' ? "" : " ";

		textEl.value = before + bspace + insert + aspace + after;
		textEl.setSelectionRange(fpos,fpos); // set cursor pos to end of text
		textEl.focus();
	} else {
		textEl.value  = textEl.value + insert; // otherwise just append
		textEl.focus()
	}
	return true;
</script>
}
richiamo funzione:
codice:
Qui va lo smile


Fai un quote del messaggio xchè il forum spezza la parola "javascript"