Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  134] [ 4]  / answers: 1 / hits: 60351  / 15 Years ago, mon, march 1, 2010, 12:00:00

I have a code that will convert lower case letters to uppercase but it works only with IE and not in Crome or Firefox.



function ChangeToUpper()
{
key = window.event.which || window.event.keyCode;

if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}



<asp:TextBox ID=txtJobId runat=server MaxLength=10 onKeypress=ChangeToUpper();></asp:TextBox>


Even I tried with



document.getElementById(txtJobId).value=document.getElementById(txtJobId).value.toUpperCase(); 


onBlur event of the textbox



What should I do to make it work in all browsers?



Thanks


More From » javascript

 Answers
24
<script type=text/javascript>
function ChangeCase(elem)
{
elem.value = elem.value.toUpperCase();
}
</script>
<input onblur=ChangeCase(this); type=text id=txt1 />


separate javascript from your HTML



window.onload = function(){
var textBx = document.getElementById ( txt1 );

textBx.onblur = function() {
this.value = this.value.toUpperCase();
};
};

<asp:TextBox ID=txt1 runat=server></asp:TextBox>


If the textbox is inside a naming container then use something like this



var textBx = document.getElementById (<%= txt1.ClientID %>);

textBx.onblur = function() {
this.value = this.value.toUpperCase();
};)

[#97461] Thursday, February 25, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ross

Total Points: 477
Total Questions: 97
Total Answers: 98

Location: France
Member since Thu, May 6, 2021
3 Years ago
;