Hi,
I am trying to reference a radTextBox through javascript to capitalize its value on blur and keypress event.
However, $find(client-Side-Object-Name) returns null in IE whereas it works fine in firefox (3.5.5).
The version of our telerik is 2008.3.1314.35
Any ideas would be appreciated,
regards,
Toby
I am trying to reference a radTextBox through javascript to capitalize its value on blur and keypress event.
However, $find(client-Side-Object-Name) returns null in IE whereas it works fine in firefox (3.5.5).
The version of our telerik is 2008.3.1314.35
| <telerik:RadScriptBlock ID="radScriptBlock" runat="server"> |
| <script type="text/javascript"> |
| AddPageLoadHandler(function() |
| { |
| AutoCapitaliseFirstChar('<%= FirstNameTextBox.ClientID %>'); |
| }); |
| </script> |
| </telerik:RadScriptBlock> |
| function AddPageLoadHandler(fn) |
| { |
| Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(fn); |
| } |
| // not created dynamically |
| <telerik:RadTextBox runat="server" ID="FirstNameTextBox" /> |
| // These client-side functions auto-capitalises text in RadTextBox as user enters it |
| // The conversion is done after a short timeout to avoid interfering with normal onfocus behaviour |
| function AutoCapitaliseFirstChar(radTextBoxClientId) { |
| var radTextBoxClientObject = $find(radTextBoxClientId); |
| // here radTextBoxClientObject is null for IE but not for firefox |
| // so it works fine with firefox not with IE 8 |
| // This converts the text when field loses focus |
| $(radTextBoxClientObject.get_element()).blur(function() { |
| setTimeout(function() { |
| var val = radTextBoxClientObject.get_value(); |
| radTextBoxClientObject.set_value(val.substring(0, 1).toUpperCase() + val.substring(1)) |
| }, 200); |
| }); |
| // Except in Safari, convert the text as it is typed |
| // (in Safari this is incompatible with the field autocomplete behaviour) |
| if (!$.browser.safari) { |
| $(radTextBoxClientObject._textBoxElement).keypress(function() { |
| setTimeout(function() { |
| var val = $(radTextBoxClientObject._textBoxElement).val(); |
| radTextBoxClientObject.set_value(val.substring(0, 1).toUpperCase() + val.substring(1)) |
| }, 200); |
| }); |
| } |
| } |
regards,
Toby

