Change Maxlength Clientside

6 posts, 0 answers
  1. Tina
    Tina avatar
    31 posts
    Member since:
    Sep 2007

    Posted 16 Mar 2009 Link to this post

    I need to change the maxlength clientside in a RadTextBox depending on a selection in a combobox.  I tried this:

     

    var txt = $find("<%= txtValue.ClientID %>");

     

     

    var item = eventArgs.get_item();

     

     

    var value = item.get_value();

     

     

    switch(value)

     

    {

     

    case "CUST_NU":

     

    txt.MaxLength = 8;

     

    break;

     

     

    case "NAME":

     

    txt.MaxLength = 30;

     

    break;

     

     

    case "CIC":

     

    txt.MaxLength = 4;

     

    break;

     

     

    case "INVOICE_NU":

     

    txt.MaxLength = 10;

     

    break;

     

    }

    Then checked for the maxlength via alert(txt.MaxLength) and it shows the new maxlength value but the textbox still doesn't change to the new length.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Mar 2009 Link to this post

    Hi Tina,

    Try the client side method set_maxLength() for setting the Maxlength of RadComboBox.

    JavaScript:
    <script type="text/javascript"
    function OnClientSelectedIndexChanged(sender, eventArgs) 
        var txt = $find("<%= txtValue.ClientID %>"); 
        var item = eventArgs.get_item(); 
        var value = item.get_value(); 
        switch(value) 
        { 
            case "CUST_NU"
                txt.set_maxLength(8); 
            break
            case "NAME"
                txt.set_maxLength(30); 
            break
            case "CIC"
                txt.set_maxLength(4); 
            break;         
        } 
    </script> 

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tina
    Tina avatar
    31 posts
    Member since:
    Sep 2007

    Posted 17 Mar 2009 Link to this post

    Thanks Shinu.  Don't know how I missed the set_maxLength function.  Too many long programming days:).  Thanks again for your help.

    Tina
  5. Heinrich
    Heinrich avatar
    2 posts
    Member since:
    Oct 2011

    Posted 19 Oct 2012 Link to this post

    Hi,

     I am having the same issue. I need to calculate the maxlength of my textbox based on another control on the page.

    I've tried explicitely setting the maxlenth using : attr('maxlength', maxlength);

    But it doesnt work, it updates the value, but when i click anywhere on the page or click on the textbox it gets reset. So I need a way of persisting this value?

    set_maxLength() also doesnt seem to work, as it doesnt affect the maxlength at all.

    Any help would be greatly appreciated.
  6. Eyup
    Admin
    Eyup avatar
    3013 posts

    Posted 23 Oct 2012 Link to this post

    Hi Heinrich,

    Currently, the set_maxLength() method takes effect when TextMode is set to MultiLine. Please try the following approach instead:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanged="indexChanged">
        <Items>
            <telerik:RadComboBoxItem Text="Two" Value="2" />
            <telerik:RadComboBoxItem Text="Three" Value="3" />
            <telerik:RadComboBoxItem Text="Four" Value="4" />
        </Items>
    </telerik:RadComboBox>
      JavaScript:
    function indexChanged(sender, args) {
        var textBox = $find("<%= RadTextBox1.ClientID %>");
        textBox.get_element().maxLength = args.get_item().get_value();
    }

    I hope this will prove helpful. Please give it a try and let me know about the result.

    Kind regards,
    Eyup
    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. Heinrich
    Heinrich avatar
    2 posts
    Member since:
    Oct 2011

    Posted 24 Oct 2012 Link to this post

    Thanks! Solved my problem. So glad to have got it working!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017