1

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?

Vishnu Y S
  • 183
  • 6
  • 18
  • possible duplicate of [JavaScript get input text value](http://stackoverflow.com/questions/11563638/javascript-get-input-text-value) –  Jul 09 '15 at 08:43

2 Answers2

3

Use value to get its value and then convert to upper case:

x=x.value.toUpperCase();
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
2

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 become uppercased then you have to use value:

x= x.value.toUpperCase();
Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175