תרגיל בנוסחאת שורשים
הודעה זו נכתבה על-ידי dj asi cohen בתאריך: 23.12.04 - שעה: 08:55:07
<html dir=rtl>
<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>
<form name=shoresh action=#null> <table border=1 width=50% bgcolor="red"> <tr> <td width=40% height=50>הכנס a</td> <td width=60% height=50><input name=num_a></td> </tr>
<tr> <td width=40% height=50>הכנס b</td> <td width=60% height=50><input name=num_b></td> </tr>
<tr> <td width=40% height=50>הכנס c</td> <td width=60% height=50><input name=num_c></td> </tr> <tr> <td width=40% height=50>מספר השורשים (לא למלאות)</td> <td width=60% height=50><input name=sug></td> </tr>
<input type=button value=חשב onclick=hashev()> </table></form>
</body>
|
יפה מאוד!! סקריפט ממש חמוד
הודעה זו נכתבה על-ידי עמרי בתאריך: 23.12.04 - שעה: 09:58:52
אני הייתי שם את התוצאה כטקסט ולא כ-Alert וכנ"ל הודעת שגיאה אם יש..
יפה מאוד, אהבתי ככןן
| |