Volevo creare una sorta di editor HTML in cui per ogni tag ( esempio: b , i , u ecc.) c'è una funzione js in cui appare un alert con un input text dove inserire una frase/parola, poi si dava l' ok e nella textarea scelta appariva esempio se si sceglieva italic , nella textarea appariva: <i>Testo/parola inserita nell' alert</i> .. Ho creato questi codici ma non funzionano, dove ho sbagliato?
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>0-c00l editor</title>
<script type="text/javascript">
function italic() {
var text = prompt("Parola:", "Testo o parola da rendere corsivo");
document.getElementById("editor").value += <i> text </i>;
}
</script>
</head>
<body>
<button value="I" onclick="italic();" />I</button><br>
<textarea name="editor" id="editor" cols="50" rows="15"></textarea>
</form>
</body>
</html>
EDIT: HO PROVATO ANCHE COSÌ MA NIENTE, SEMBRA NON 'LEGGERE' IL JS:
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>0-c00l editor</title>
<script type="text/javascript">
function italic() {
var text = prompt("Parola:", "Testo o parola da rendere corsivo");
document.formeditor.editor.value += <i> text </i>;
}
</script>
</head>
<body>
<form action="" method="post" name="formeditor">
<input type="button" value="I" onclick="italic();" /><br>
<textarea name="editor" id="editor" cols="50" rows="15"></textarea>
</form>
</body>
</html>