- 7
- 0
- CPU
- Intel(R) Core(TM)2 Duo CPU T5800 2,00GHz
- Scheda Madre
- Sony Vaio
- RAM
- DDR2 3072 MBytes
- GPU
- ATI Mobility Radeon HD 3470
- OS
- Windows Vista 32 bit
Buonasera, giusto per iniziare col JS ho provato a realizzare questo semplice codice per risolvere un'equazione di secondo grado. Il problema è che nel momento in cui clicco sul bottone, il risultato appare nel paragrafo #result però scompare subito, mentre vorrei che restasse visibile (:
Codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Risoluzione equazione di secondo grado</title>
<script>
function _sol() {
var a=parseInt(document.Equazione.a.value);
var b=parseInt(document.Equazione.b.value);
var c=parseInt(document.Equazione.c.value);
var d=Math.sqrt(b*b-4*a*c);
if((a==0)||(d<0))
alert("Impossibile risolvere l'equazione");
else
{
var x1 = (-b + d ) / (a*2);
var x2 = (-b - d ) / (a*2);
document.getElementById("result").innerHTML=x1;}
}
</script>
</head>
<div align="center">
<form name="Equazione">
<h1>Equazione di 2° grado</h1><br />
<input type="text" name="a" />x<sup>2</sup> + <input type="text" name="b" />x + <input type="text" name="c" /><br />
<button onclick="_sol()">Risolvi</button></form>
Il risultato è: <span id="result"></span>
</div>
<body>
</body>
</html>