Lo faccio con una JSP perché è più corta e sono svogliato.
Pagina con form senza submit
codice:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Form Page</title>
<script language="javascript" type="text/javascript">
function processForm(i) {
var f = document.getElementById("mioform");
f.elements['additionalParameter'].value = i;
f.submit();
}
</script>
</head>
<body>
<h1>Un form senza submit apparente</h1>
<form name="mioform" id="mioform" method="post" action="processform.jsp">
<textarea name="miatextarea">Testo di default</textarea>
<input type="hidden" name="additionalParameter" value="0" />
Testo rosso
Testo verde
</form>
</body>
</html>
Pagina processa form
codice:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pagina Processa Form</title>
</head>
<body>
<h1>Testo Inviato</h1>
<%
int i = 0;
try {
i = Integer.parseInt(request.getParameter("additionalParameter"));
}
catch (Exception e) {
i = 0;
}
String[] colors = {"#F00", "#0F0"};
out.println("<span style=\"color:"+colors[i]+"\";>"+request.getParameter("miatextarea")+"</span>");
%>
</body>
</html>