I am using the following style attribute to set the user input to uppercase so that when the user starts typing in the text box for example railway
, then it should
The answers with the text-transformation:uppercase
styling will not send uppercased data to the server on submit - what you might expect. You can do something like this instead:
For your input HTML use onkeydown:
In your JavaScript:
function upperCaseF(a){
setTimeout(function(){
a.value = a.value.toUpperCase();
}, 1);
}
With upperCaseF()
function on every key press down, the value of the input is going to turn into its uppercase form.
I also added a 1ms delay so that the function code block triggers after the keydown event occured.
UPDATE
Per remommendation from Dinei, you can use oninput event instead of onkeydown and get rid of setTimeout
.
For your input HTML use oninput: