<head> <meta http-equiv=Content-Language content=he> <meta http-equiv=Content-Type content=text/html; charset=windows-1255> <title>נוסחת השורשת</title> </head> <body> <script> function hashev() { //בדיקת נתונים var tofes=document.shoresh; var reg=/<^1234567890->/;
if (tofes.num_a.value=='' || tofes.num_b.value=='' || tofes.num_c.value=='') { alert ('עליך למלאות את כל השדות'); return; }
if (reg.test(tofes.num_a.value) || reg.test(tofes.num_b.value) || reg.test(tofes.num_c.value) ){ alert ('הנתונים שהזנת אינם חוקיים\n עליך לכתוב מספרים בלבד.'); return; }
if (tofes.num_a.value==0){alert('a לא יכול ליהיות שווה ל0');return;}
//סיום הבדיקה. תחילת חישוב var a=tofes.num_a.value; var b=tofes.num_b.value; var c=tofes.num_c.value; var d=b*b-4*a*c; //alert(d);
if (d>0){ tofes.sug.value="שני שורשים שונים הוצגו"; var x_one=(-1*b+Math.sqrt(d))/(2*a); var x_two=(-1*b-Math.sqrt(d))/(2*a); alert('x1=' + x_one);alert('X2='+ x_two); } if (d<0){tofes.sug.value="אין שורשים, לכן שום דבר לא הוצג.";} if (d==0){tofes.sug.value="שורש אחד"; var x_one=(-1*b+Math.sqrt(d))/(2*a); alert('x_one=' + x_one);} } </script>