I have a function to capitalize onchange like this:
<input type="text" id="abc" name="id" onchange="capitalize()">
And function definition is as follows:
<script>
function capitalize()
{
var x= document.getElementById('abc');
x=x.toUpperCase();
document.getElementById('abc').value=x;
}
</script>
I get the error as:
Uncaught TypeError: x.toUpperCase is not a function
What changes should I make or should I include any header files?
I have a function to capitalize onchange like this:
<input type="text" id="abc" name="id" onchange="capitalize()">
And function definition is as follows:
<script>
function capitalize()
{
var x= document.getElementById('abc');
x=x.toUpperCase();
document.getElementById('abc').value=x;
}
</script>
I get the error as:
Uncaught TypeError: x.toUpperCase is not a function
What changes should I make or should I include any header files?
Share Improve this question edited Jul 9, 2015 at 8:55 Vishnu Y S asked Jul 9, 2015 at 8:37 Vishnu Y SVishnu Y S 1936 silver badges19 bronze badges 1- possible duplicate of JavaScript get input text value – user663031 Commented Jul 9, 2015 at 8:43
2 Answers
Reset to default 3Use value to get its value and then convert to upper case:
x=x.value.toUpperCase();
You can't make an element into uppercase. You are calling it on the input itself, not the value. If you want the value to bee uppercased then you have to use value
:
x= x.value.toUpperCase();