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.
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2009, 07:43 AM
Hi Tina,
Try the client side method set_maxLength() for setting the Maxlength of RadComboBox.
JavaScript:
Thanks,
Shinu.
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.
0
Tina
Top achievements
Rank 2
answered on 17 Mar 2009, 12:01 PM
Thanks Shinu. Don't know how I missed the set_maxLength function. Too many long programming days:). Thanks again for your help.
Tina
Tina
0
Heinrich
Top achievements
Rank 1
answered on 19 Oct 2012, 09:23 AM
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.
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.
0
Hi Heinrich,
Currently, the set_maxLength() method takes effect when TextMode is set to MultiLine. Please try the following approach instead:
JavaScript:
I hope this will prove helpful. Please give it a try and let me know about the result.
Kind regards,
Eyup
the Telerik team
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
>
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.
0
Heinrich
Top achievements
Rank 1
answered on 24 Oct 2012, 08:09 AM
Thanks! Solved my problem. So glad to have got it working!