Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. stuck in loop by seting focus using javascript

stuck in loop by seting focus using javascript

Scheduled Pinned Locked Moved ASP.NET
helpjavascript
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DineshSharmain
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • D DineshSharmain

      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

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      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... "

      D 1 Reply Last reply
      0
      • S Sandeep Akhare

        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... "

        D Offline
        D Offline
        DineshSharmain
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • D DineshSharmain

          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

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          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... "

          D 1 Reply Last reply
          0
          • S Sandeep Akhare

            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... "

            D Offline
            D Offline
            DineshSharmain
            wrote on last edited by
            #5

            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

            S C 2 Replies Last reply
            0
            • D DineshSharmain

              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

              S Offline
              S Offline
              Sandeep Akhare
              wrote on last edited by
              #6

              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... "

              1 Reply Last reply
              0
              • D DineshSharmain

                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

                C Offline
                C Offline
                Cfer83
                wrote on last edited by
                #7

                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();

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups