لدي حقل خاص بتسجيل السجل المدني
كيف اتحقق من ان المدخل عشر ارقام فقط
وجزكم الله خير
لدي حقل خاص بتسجيل السجل المدني
كيف اتحقق من ان المدخل عشر ارقام فقط
وجزكم الله خير
<!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>
<title>Untitled Page</title>
<script type="text/javascript">
function checknumber()
{
var str=document.getElementById('number').value;
if(isNaN(parseInt(str)))
{
// alert("Number is not valid");
document.getElementById("x").style.backgroundColor="red";
document.getElementById("x").innerHTML="Number is not valid";
return false;
}
else
{
if(str.length==10)
{
document.getElementById("x").style.backgroundColor="green";
return true;
}
else{
document.getElementById("x").style.backgroundColor="red";
// alert("your number must have 10 digit numbers");
document.getElementById("x").innerHTML="your number must have 10 digit numbers";
return false;
}
}
}
</script>
</head>
<body>
<form id="f1" action="" onsubmit="return checknumber();" >
<input type="text" id="number" />
<input type="submit" value="Submit" />
</form>
<div id="x"
style="position:absolute; top: 16px; left: 237px; height: 25px;">
</div>
</body>
</html>تم تعديل هذه المشاركة بواسطة X-File في 26 نوفمبر 2010 في 16:19
In bad state
جزاك الله خير اخوي
جزانا اجمعين
لمزيد من التوضيح
<!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>Untitled 1</title>
<script type="text/javascript">
<!--
function ch()
{
var count=document.getElementById('t').value;
if(isNaN(parseInt(count)))
{
document.getElementById("img").src="error.jpg";
document.getElementById("ouput").style.visibility="visible";
document.getElementById("ouput").innerHTML="you are must enter numbers";
document.getElementById("B").disabled="disabled";
}
else
{
if(count.length==10)
{
document.getElementById("img").src="true.jpg";
document.getElementById("B").disabled="";
}
else
{
document.getElementById("ouput").innerHTML="";
document.getElementById("img").src="error.jpg";
document.getElementById("B").disabled="disabled";
}
}
}
function x(keycode)
{
if((keycode >95) && (keycode<106) || (keycode==8) || (keycode==46))
{
var o=document.getElementById('t').value;
if((o.length<10) ||(keycode==8) || (keycode==46) )
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
function b()
{
var doc=document.getElementById('t').value;
if(isNaN(parseInt(doc)) || (doc.length>10))
{
return false;
}
else
{
return true;
}
}
//-->
</script>
</head>
<body>
<input type="text" id="t" onkeydown="return x(event.keyCode);" onkeyup="ch();" onPaste="return b();" onCopy="return false;" onCut="return false;" />
<div id="ouput" style="position:absolute;top:19%; left:1%; width:302px; height:100px; visibility:hidden;">
</div>
<input id="B" type="button" disabled="disabled" value="click me" /> <br />
<img id="img" src="" alt="" /><br />
</body>
</html>In bad state
أخواني جزاكم الله خير اعرف أن الموضوع قديم
ولكن لأنه لدي سؤال بهذا الخصوص ولا اردت ان افتح موضوع جديد
اريد تطبيق نفس الخطوات السابقة و اريد ان يتحقق من سجلين وليس سجل واحد
مثال رقم الطالب من 5 ارقام فقط
والسجل المدني من 10 ارقام
كيف يمكن تطبيق هذه العملية
وحزاكم الله خير
مرر الـ id الخاص بالعنصر، واستخدمه بدل 't' الثابتة.
قمت بتعديل الكود:
<!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>Untitled 1</title>
<script type="text/javascript">
<!--
function ch(id)
{
number = document.getElementById(id).value;
if (!isNaN(number) && number.length == 10)
{
document.getElementById("img").src="true.jpg";
document.getElementById("B").disabled="";
}
else
{
document.getElementById("ouput").innerHTML="";
document.getElementById("img").src="error.jpg";
document.getElementById("B").disabled="disabled";
}
}
function x(keycode, id)
{
if((keycode >= 47) && (keycode <= 58) || keycode==8)
{
number = document.getElementById(id).value;
if (number.length <= 10)
return true;
else
return false;
}
return false;
}
function b(id)
{
number = document.getElementById(id).value;
if(isNaN(parseInt(number)) || (number.length > 10))
return false;
else
return true;
}
//-->
</script>
</head>
<body>
<input type="text" id="t" onkeydown="return x(event.keyCode, this.id);" onkeyup="ch(this.id);" onPaste="return b(this.id);" onCopy="return false;" onCut="return false;" maxlength=10 />
<div id="ouput" style="position:absolute;top:19%; left:1%; width:302px; height:100px; visibility:hidden;"></div>
<input id="B" type="button" disabled="disabled" value="click me" /> <br />
<img id="img" src="" alt="" />
</body>
</html>Do as I say, not as I do
We are Anonymous. We are Legion. We don't forgive. We don't forget
اخواي جزاك الله خير
ياليت تكمل جميلك
انا خبرتي في الجافا سكربت ضعيفه جداً
انا اريد مربعين نص
رقم الطالب :
رقم السجل المدني :
إذا كان رقم الطالب اقل من 5 ارقام او اكثر بالإضافة الى السجل المدني اقل من 10 ارقام او اكثر
تظهر رسالة
وجزاك الله خير ولا حرمك الأجر
المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية
جارٍ التحقق من المتواجدين…