فى هذا الاسكربت سوف اقوم بعمل textbox لا سمح بكتابة الحروف فقط و اى شيئ اخر لن يسمح بكتابتة
اسف الموضوع بالانجليزى لكن لضيق الوقت لم اتمكن من ترجمتة للعربي اسف و نبدء
1- In that Article i will write script control TextBox have a value " Enter String Only " when use click on TextBox Become Blank when user delete written value " Enter String Only " Back agane in Textbox and If user try To write Non String character in TextBox that character will not be written.
inputtext_onclick()
That Funcation responsible on Delete " Enter String Only " words if it written and set fulltext_befor_new_char variable to "" ( I will describe that variable useing next ) or set fulltext_befor_new_char to TextBox value that Funcation fire when use click on TextBox
.
function inputtext_onclick()
{
// if the TextBox value = "Enter String Only" that mean // the use not written any words yat so set the textbox // value to "" and fulltext_befor_new_char Variable to ""
if ((TextBox_Element.value == "Enter String Only"))
{
TextBox_Element.value="";
fulltext_befor_new_char = "";
}
Else
// else mean mean the user written words befor as save it in //fulltext_befor_new_char Variable
fulltext_befor_new_char = TextBox_Element.value;
}inputtext_onblur()
That Funcation responsible on rewrite " Enter String Only" words if the user don't write any words that Funcation fire when TextBox lost Focus.
function inputtext_onblur()
{
// if the textbox value = "" then the use laft the text box empty so //set textbox value to "Enter String Only" agane
if ((TextBox_Element.value == ""))
TextBox_Element.value="Enter String Only";
}inputtext_onkeyup()
That Funcation responsible on cheak if the use write legal character or illegal one if illegal set the textbox value to fulltext_befor_new_char variable ( I think the describe that variable using) that Funcation fire when TextBox key up.
function inputtext_onkeyup()
{
var fulltext = TextBox_Element.value;
// if character illegal then set the texbox value to //fulltext_befor_new_char ( the old textbox value )
if (!Filter(fulltext))
{
TextBox_Element.value = fulltext_befor_new_char;
}}
inputtext_onkeypress()
That Funcation responsible on cheak if the use write legal character or illegal one if illegal set the textbox value to fulltext_befor_new_char variable if legal save the TextBox value in fulltext_befor_new_char variable ( now you may say that funcation almost do same as inputtext_onkeyup() Funcation yes but user maybe kep press on an illegal character and inputtext_onkeyup() Funcation will fire just one time ) that funcation will fire when TextBox key press .
function inputtext_onkeypress()
{
var fulltext = TextBox_Element.value;
// if character legal then save textbox value in //fulltext_befor_new_char Variable texbox value to
if (Filter(fulltext))
{
fulltext_befor_new_char = TextBox_Element.value;
}
Else
// if character illegal then set the texbox value to //fulltext_befor_new_char ( old textbox value )
{
TextBox_Element.value = fulltext_befor_new_char;
}
}Filter(Filter_Text)
That Funcation responsible on cheak if that value is legal or illegal it return ( true or false ).
function Filter(Filter_Text)
{
var Return_value = true;
var Filter=/^[a-zA-Z]+$/;
// if testbox value = "" that's mean true
if ( Filter_Text != "" )
{
// if textbox value not meet regex expression set Return_value to false
if (!Filter.test(Filter_Text))
{
Return_value = false;
}
}
Else
// if textbox value meet regex expression set Return_value Variable to true
{
Return_value = true;
}
// Return Return_value Variable
return Return_value;
}add_Events_To_TextBox(TextBox_Name_Client)
That Funcation responsible on adding (onkeyup – onclick – onblur – onkeypress ) Events to textbox in RunTime that Funcation fire aftar document on page Load .
function add_Events_To_TextBox(TextBox_Name_Client)
{
// save the textbox element in TextBox_Element Variable so we // can use it any time in all the script
TextBox_Element = document.getElementById(TextBox_Name_Client);
// set TextBox_Element elent onkeyup event
TextBox_Element.onkeyup=inputtext_onkeyup;
// set TextBox_Element elent onclick event
TextBox_Element.onclick=inputtext_onclick;
// set TextBox_Element elent onblur event
TextBox_Element.onblur=inputtext_onblur;
// set TextBox_Element elent onkeypress event
TextBox_Element.onkeypress = inputtext_onkeypress;
}In aspx file wrire at end of <form></form> Element
<script language="javascript" type="text/javascript" src="Unwrite_aspx.js" >
</script>
<script language="javascript" type="text/javascript" >
add_Events_To_TextBox("<%=Unwrite_TestBox.ClientID%>");
</script>
Happy coding …الاسكربت كامل فى المرفقات
لو عجبك الاسكربت ممكن ترشحو فى كود برجكت شكرا