disable focus textbox

22 posts, 0 answers
  1. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 13 Jan 2012 Link to this post

    I am with two textbox but wanted to make when one of them lose focus disables the other. this code works on components vb 2010 example:
    $('#<%= RadTextBox2.ClientID %>').change(function (e) {

             var targetControl1 = $('#<%= RadTextBox1.ClientID %>');
             var targetControl2 = $('#<%= RadTextBox2.ClientID %>');

             if (targetControl1.val() == "") {
                 targetControl1.attr('disabled', 'disabled');

             }


         });

         $('#<%= RadTextBox2.ClientID %>').focusin(function (e) {

             var targetControl1 = $('#<%= RadTextBox1.ClientID %>');
             var targetControl2 = $('#<%= RadTextBox2.ClientID %>');

             if (targetControl2.val() == "") {
                 targetControl1.removeAttr('disabled', 'disabled');

             }
         });
         $('#<%= RadTextBox1.ClientID %>').change(function (e) {

             var targetControl1 = $('#<%= RadTextBox1.ClientID %>');
             var targetControl2 = $('#<%= RadTextBox2.ClientID %>');

             if (targetControl2.val() == "") {
                 targetControl2.attr('disabled', 'disabled');

             }


         });
         $('#<%= RadTextBox1.ClientID %>').focusin(function (e) {

             var targetControl1 = $('#<%= RadTextBox1.ClientID %>');
             var targetControl2 = $('#<%= RadTextBox2.ClientID %>');

             if (targetControl1.val() == "") {
                 targetControl2.removeAttr('disabled', 'disabled');

             }
         });
    no works !
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 16 Jan 2012 Link to this post

    Hello Toboy,

    If you're using the latest version of RadControls, you should turn on EnableSingleInputRendering="true", in order to access the input element as you have it now, otherwise you will need to append "_text" to your id's, as that's how you access the input element when EnableSingleInputRendering is turned off.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 16 Jan 2012 Link to this post

    To add to my previous post, you could also handle the OnValueChanging/OnValueChanged and OnFocus events of the RadTextBox to achieve the same result. You will just need to use the RadTextBox client-side api to toggle the disabled state and check that control's value.
  5. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 25 Jan 2012 Link to this post

    Can you give me an example of how my code would be because I tried but I will get the version I'm using v.2011.3.1115.40 will be grateful!
  6. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 25 Jan 2012 Link to this post

    Hi Toboy,

    Here is an example:
    var input1= $find('<%= RadTextBox1.ClientID %>');
    input1.disable();
    Check this help topic for more information on the client side functions of RadInput's object:
    http://www.telerik.com/help/aspnet-ajax/input-client-side-radtextbox.html

    Regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  7. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 25 Jan 2012 Link to this post

    I am new to java can be more clear where I call this code <telerik: RadTextBox id = "RadTextBox2" runat = "server" Height = "15px" Width = "300px"
                                 ValidationGroup = "Representative" onvaluechange = "btnSend_onclick"> </ telerik: RadTextBox>


       btnSend_onclick function () {
           var input1 = $ find ('<%= RadTextBox1.ClientID %>');
           input1.disable ();

                var input1 = $ find ('<%= RadTextBox2.ClientID %>');
           input1.disable ();
                
               

             }

    and <telerik: RadTextBox id = "RadTextBox1" runat = "server" Height = "15px" Width = "300px"
                                 ValidationGroup = "Representative" onvaluechange = "btnSend_onclick"> </ telerik: RadTextBox>

    Remembering that my purpose is when a RadTextBox lose focus and disable the other and enabled RadTextBox2

    Can you help me how will be my code.
  8. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 26 Jan 2012 Link to this post

    Hello Toboy,

    Here is an workable sample. After the page loads, the TextBox2 gets disabled. Then when you enter value in the TextBox1, it get disabled, and the TextBox2 becomes enabled.
    <script type="text/javascript">
       function textBox1valueChanged(sender, args)
       {
         sender.disable();
         var textBox2 = $find("<%=RadTextBox2.ClientID %>");
         textBox2.enable();
       }
       function disableThis(sender, args)
       {
         sender.disable();
       }
     </script>
     <telerik:RadTextBox runat="server" ID="RadTextBox1">
       <ClientEvents OnValueChanged="textBox1valueChanged" />
     </telerik:RadTextBox>
     <telerik:RadTextBox runat="server" ID="RadTextBox2">
       <ClientEvents OnLoad="disableThis" />
     </telerik:RadTextBox>


    Regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  9. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 26 Jan 2012 Link to this post

    Sorry but what I wanted was for both to stay active on page load only be disabled when entering some value in a field. example:

    when I type in the textbox1 textbox2 the disabled and when I goes out the contents of a textbox to enable the textbox 2 and so respectively.

    I have a study that textbox1 from codes and performs textbox2 by description, when one of them disables the other is filled by the two can not seek the same time
  10. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 26 Jan 2012 Link to this post

    your code works only when I disable the postback it is my intention to disable it the other field only when it lose focus, because when I disable the postback it the same field that I'm using.
  11. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 26 Jan 2012 Link to this post

    I tried but did not work this way: he wanted to disable only when you lose your focus

     
                
       
    <script type="text/javascript" id="telerikClientEvents5">
    //<![CDATA[
     
        function RadTextBox1_OnFocus(sender,args)
        {
             
            var textBox2 = $find("<%=RadTextBox2.ClientID %>");
            textBox2.enable();
            if (textBox2.val() == "") {
             sender.disable(); 
     
            }
        }
    //]]>
    </script>
        
        
        
        <script type="text/javascript" id="telerikClientEvents6">
    //<![CDATA[
     
        function RadTextBox2_OnFocus(sender,args)
        {
           
            var textBox1 = $find("<%=RadTextBox1.ClientID %>");
            textBox1.enable();
            if (textBox1.val() == "") {
             sender.disable(); 
        }
    //]]>
    </script>

       

  12. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 26 Jan 2012 Link to this post

    Hi,

    If you want to perform action on loosing focus, you could use the Blur event:
    http://www.telerik.com/help/aspnet-ajax/input-client-side-onblur.html

    Greetings,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  13. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 26 Jan 2012 Link to this post

     

    how would my code to disable the textbox when it loses its focus, as I said I am new to java can help me, I tried to introduce what I already had and did not work  .

    example :

    $('#<%= RadTextBox2.ClientID %>').change(function (e) 
    {        var targetControl1 = $('#<%= RadTextBox1.ClientID %>');        
    var targetControl2 
    = $('#<%= RadTextBox2.ClientID%>');       
    if 
    (targetControl1.val() == ""
    {             
    targetControl1.attr('disabled','disabled');       
    }   
    });



  14. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 27 Jan 2012 Link to this post

    Hi Toboy,

    Here is an example how to disable the RadTextBox after it loses its focus.

    <script type="text/javascript">
      function RadTextBox1BlurHandler(sender, args)
      {
        sender.disable();
      }
    </script>
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
      <ClientEvents OnBlur="RadTextBox1BlurHandler" />
    </telerik:RadTextBox>


    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  15. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 28 Jan 2012 Link to this post

    and if I want to use it again after he lost the focus I just click on it it works ?
  16. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 30 Jan 2012 Link to this post

    Hi Toboy,

    You can not click it later, because it is disabled. In order to be able to click it, you need to enable it first.

    However from what you written, I believe that you need to style the textbox differently depending if it is on focus or not, and not to disable it. If I am correct in this assumption please see these resources:
    http://www.telerik.com/help/aspnet-ajax/input-styles.html
    http://demos.telerik.com/aspnet-ajax/input/examples/appearance/styles/defaultcs.aspx

    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  17. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 06 Feb 2012 Link to this post

    and how do I enable it again in my old code enabled the textbox that he was disabled when the fields were clean he would return to work, as I have to do this check in your code
  18. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 08 Feb 2012 Link to this post

    Hello Toboy,

    Well to enable the RadTextBox you could use the .enable() function like:
    var textBox1 = $find("<%=RadTextBox1.ClientID %>");
    textBox1.enable();

    If you still have troubles with your implementation, please give us more detailed explanations of the scenario that you want to achieve. When you need to disable the textboxes, and when you need to enable them? Are they are only two textboxes? Do you need to change the enable/disable state of one of them depending changes of the other one?

    All the best,
    Vasil
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  19. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 10 Feb 2012 Link to this post

    must activate when the boxes are off and you were doing when one of the boxes have been chosen

    example: I have two search fields radtextbox a search for the code part 2 radtextbox search for part description

    when the User to choose a radtextbox radtextbox 2 is disabled and is cleared when the radtextbox both fields should be activated
  20. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 15 Feb 2012 Link to this post

    Hi,

    So you need to disable the other textbox when the first one has text entered. And if they both are empty they should be enabled. If this is correct, here is the code:
    <script type="text/javascript">
      function rtb1BlurHandler(sender, args)
      {
        if (sender.get_value() == "")
          $find("<%=rtb2.ClientID %>").enable();
        else
          $find("<%=rtb2.ClientID %>").disable();
      }
      function rtb2BlurHandler(sender, args)
      {
        if (sender.get_value() == "")
          $find("<%=rtb1.ClientID %>").enable();
        else
          $find("<%=rtb1.ClientID %>").disable();
      }
    </script>
    <telerik:RadTextBox runat="server" ID="rtb1" ClientEvents-OnBlur="rtb1BlurHandler">
    </telerik:RadTextBox>
    <telerik:RadTextBox runat="server" ID="rtb2" ClientEvents-OnBlur="rtb2BlurHandler">
    </telerik:RadTextBox>

    Regards,
    Vasil
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  21. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 17 Feb 2012 Link to this post

    exactly the same thanks for the help
  22. Toboy
    Toboy avatar
    28 posts
    Member since:
    Jan 2012

    Posted 27 Feb 2012 Link to this post

    each textbox I have a button I use, I can make the textbox to be populated he can give the focus on the desired button example:

    <script type="text/javascript">
      function rtb1BlurHandler(sender, args)
      {
        if (sender.get_value() == "")
          $find("<%=rtb2.ClientID %>").enable();
             RadButton1.focus
        else
          $find("<%=rtb2.ClientID %>").disable();

  23. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 28 Feb 2012 Link to this post

    Hi Toboy,

    To focus the button you could use its focus() method like:
    $find("<%=RadButton1.ClientID %>").focus();
    For more information see this help topic:
    http://www.telerik.com/help/aspnet-ajax/button-client-side-basics.html

    Greetings,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017