stuck in loop by seting focus using javascript
-
Hi I have two text boxes and written the javascript function for both that will be fired onblur event. i put the condition in javascript function function Check(Obj) { if(Obj.value==0) Obj.focus() } and calling as: problem is before calling the onblur event focus goes to second textbox and simultaneouly call the Check function for first textbox that set the focus for tBox1 and so now Check() function calling for tBox2.......and stuck in loop........ please give me any solution:confused:......Thanks
Dinesh Sharma
-
Hi I have two text boxes and written the javascript function for both that will be fired onblur event. i put the condition in javascript function function Check(Obj) { if(Obj.value==0) Obj.focus() } and calling as: problem is before calling the onblur event focus goes to second textbox and simultaneouly call the Check function for first textbox that set the focus for tBox1 and so now Check() function calling for tBox2.......and stuck in loop........ please give me any solution:confused:......Thanks
Dinesh Sharma
What is your scenario ? what you want to do ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
What is your scenario ? what you want to do ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
thanks to pay your attention... my scenario is to validate two textboxes on focus lost if validated then move focus to next box else remain the focus on tBox1.
Dinesh Sharma
-
thanks to pay your attention... my scenario is to validate two textboxes on focus lost if validated then move focus to next box else remain the focus on tBox1.
Dinesh Sharma
Strange !! so if user enters the something in the textbox at the same time you want to validate it if it is proper then move to textbox2 Try it NameTxtBx.Attributes.Add("OnBlur", "javascript:MakeSum('NameTxtBx');"); Call this javascipt function on first textbox blur javascript var tags=document.getElementById('NameTxtBx'); var tags2=document.getElementById('AdressTxtBx'); alert(tags.value.length); if(tags.value.length==0) { tags.focus(); } else if(tags.value>0) { tags2.focus(); }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Strange !! so if user enters the something in the textbox at the same time you want to validate it if it is proper then move to textbox2 Try it NameTxtBx.Attributes.Add("OnBlur", "javascript:MakeSum('NameTxtBx');"); Call this javascipt function on first textbox blur javascript var tags=document.getElementById('NameTxtBx'); var tags2=document.getElementById('AdressTxtBx'); alert(tags.value.length); if(tags.value.length==0) { tags.focus(); } else if(tags.value>0) { tags2.focus(); }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
thanks buddy for your quick reply.........:) but my problem is that i m validating the value (entered by user) onblur. if value is ok then move to next text box else focus remain to same textbox. same condition is with next textbox. but what is happening with me .....before firing the onblur event for tBox1 focus goes to next textbox (tBox2) and then onblur function called for tBox1. but as tBox2 got the focus automatically and my function is setting the focus to tBox1 'coz' of wrong value. so tBox2 also fire the event onblur and it happens continuously............. function Check(Ntxt) { switch(Ntxt.id) { case "tBox1": if(Ntxt.value.length<11) Ntxt.focus(); break; case "tBox2": if(Ntxt.value.length<10) Ntxt.focus(); break; } } calling the function TextBox1.Attributes.Add("onblur", "Check(this)"); TextBox2.Attributes.Add("onblur", "Check(this)"); assume both the textbox's condition is false Thanks
Dinesh Sharma
-
thanks buddy for your quick reply.........:) but my problem is that i m validating the value (entered by user) onblur. if value is ok then move to next text box else focus remain to same textbox. same condition is with next textbox. but what is happening with me .....before firing the onblur event for tBox1 focus goes to next textbox (tBox2) and then onblur function called for tBox1. but as tBox2 got the focus automatically and my function is setting the focus to tBox1 'coz' of wrong value. so tBox2 also fire the event onblur and it happens continuously............. function Check(Ntxt) { switch(Ntxt.id) { case "tBox1": if(Ntxt.value.length<11) Ntxt.focus(); break; case "tBox2": if(Ntxt.value.length<10) Ntxt.focus(); break; } } calling the function TextBox1.Attributes.Add("onblur", "Check(this)"); TextBox2.Attributes.Add("onblur", "Check(this)"); assume both the textbox's condition is false Thanks
Dinesh Sharma
One thing is that disable the second textbox untill validation of first textbox is not valid ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
thanks buddy for your quick reply.........:) but my problem is that i m validating the value (entered by user) onblur. if value is ok then move to next text box else focus remain to same textbox. same condition is with next textbox. but what is happening with me .....before firing the onblur event for tBox1 focus goes to next textbox (tBox2) and then onblur function called for tBox1. but as tBox2 got the focus automatically and my function is setting the focus to tBox1 'coz' of wrong value. so tBox2 also fire the event onblur and it happens continuously............. function Check(Ntxt) { switch(Ntxt.id) { case "tBox1": if(Ntxt.value.length<11) Ntxt.focus(); break; case "tBox2": if(Ntxt.value.length<10) Ntxt.focus(); break; } } calling the function TextBox1.Attributes.Add("onblur", "Check(this)"); TextBox2.Attributes.Add("onblur", "Check(this)"); assume both the textbox's condition is false Thanks
Dinesh Sharma
why don't you do it like this: using enabled or readonly properties you can make sure your user follows the correct direction you intended. textbox1.enabled = true; textbox2.enabled = false; Textbox1 Events onblur: if tbox1.value = "" { tbox1.setFocus(); } else tbox2.enabled = true; TextBox2 Events onblur: if tbox2.value = "" tbox2.SetFocus();