الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ممكن احد يوضح لي المشكلة فين؟؟

بدأه stest في 23 نوفمبر 2010 · 4 رد · 648 مشاهدة · في قسم البرمجة بــ Javascript
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

هذا اول كود اعمله باجافا سكريبت

وهو جدا بسيط لكن ماافهمت المشكلة وين بالضبط ماابيشتغل معي مع اني احسه منطقي

فاتمنى اي متخصص يخف شوي علي ويوضح لي فين المشكلة

انا حابه اليوزر يدخل لي درجة الحرارة في الفورم وبناء على ذلك اغير خلفية الصفحة وقبل كل شيء لازم اتاكد انو المستخدم دخل رقم وان الفورم غير فارغ

<html xmlns = "http://www.w3.org/1999/xhtml">

<head><title>temprature </title>

<script type = "text/javascript">

function validate_required(){

{

var temprature=parsInt(myform.tempratureBottun.value);

if (temprature==null||temprature=="")

{

alert("please Enter temprature ");

}

else

{

startChange(temprature) ;

}

}

}

function startChange(temp1)

{

if(temp1<30){ document.body.style.backgroundColor =#00CCFF ;}

else

if(temp1>30 && temp1<50){ document.body.style.backgroundColor =#CCFF33 ;}

else

if(temp1>50){ document.body.style.backgroundColor = #FF3333 ;}

}

</script>

</head>

<body>

<form name="myform" action="">

<p>City temprature:

<input name = "tempratureBottun" type = "text" />

</p>

<p>

<input name= "Enter" type = "button" value = "Enter" onclick="validate_required()" />

</p>

</form>

</body>

</html>

تم تعديل هذه المشاركة بواسطة stest في 23 نوفمبر 2010 في 16:39

#2

تفضل :wink:

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>temperature</title>
<script type="text/javascript">
function validate_required(){
{
var temperature=parseInt(myform.temperatureButton.value);
if (isNaN(temperature) == 1)
{
alert("please Enter temperature ");
}
else
{
startChange(temperature);
}
}
}
</script>
<script type="text/javascript">
function startChange(temp1) 
{
if(temp1<30){ document.body.style.backgroundColor ='#00CCFF' ;}
else 
if(temp1>30 && temp1<50){ document.body.style.backgroundColor ='#CCFF33' ;}
else

if(temp1>50){ document.body.style.backgroundColor = '#FF3333' ;}
}
</script>
</head>
<body>
<form name="myform" id="myform" action="">
<p>City temperature:
<input name="temperatureButton" id="temperatureButton" type="text" />
</p>
<p> 
<input name="Enter" type="button" value="Enter" onclick="validate_required()" /> 
</p> 
</form>
</body>
</html>

parsInt جعلتها parseInt

وعدلت جملة If

وأكواد الألوان وضعتها بين علامات تنصيص '

تم تعديل هذه المشاركة بواسطة 0xAli في 23 نوفمبر 2010 في 17:01

A man who wants to lead the orchestra must turn his back on the crowd

#3

بار ك الله فيك اخي 0xAli

بصراحة امر محرج ان اخطيء في سبلينق الكلمة :\

لكن عندي اسئلةاذا سمحت؟؟

لماذا عملت هذه

i

f (isNaN(temperature) == 1)

ولم تعمل

if (temprature==null||temprature=="")

التي كتبتها في ردي الاول مع انها منظقية ؟؟

وبوركت مره اخرى استاذنا

#4
stest كتب:

بار ك الله فيك اخي 0xAli

بصراحة امر محرج ان اخطيء في سبلينق الكلمة :\

لكن عندي اسئلةاذا سمحت؟؟

لماذا عملت هذه

if (isNaN(temperature) == 1)

ولم تعمل

if (temprature==null||temprature=="")

التي كتبتها في ردي الاول مع انها منظقية ؟؟

هي فعلاً يا أخي منطقية, لكن في التحقق من الحروف strings لكن temprature الآن هي ناتج دالة parseInt والتي تكون إما NaN -Not a Number- أو رقم وفي كلا الحالتين ستكون المقارنة غير مجدية, لأن الناتج لن يكون أبداً null او فارغ.

تحياتي.

A man who wants to lead the orchestra must turn his back on the crowd

#5

بارك الله فيك

اخي وشكرا جزيلا

جوابك مقنع ومنطقي بوركت مره اخرى

مواضيع مشابهة