64
rated 0 times
[
67]
[
3]
/ answers: 1 / hits: 11444
/ 10 Years ago, sat, april 19, 2014, 12:00:00
I'm trying to change a form input field (username) to uppercase and to remove all spaces within the text. I know there are a few ways one could do this but I need to figure out how to do this using a function. I need to get the input by it's id and use the toUpperCase method but I cannot figure this out for the life of me. As you might be able to tell, I am new to JavaScript. Any help would be greatly appreciated. Thank you.
HTML:
<div class=login-form>
<h1 class=h1-login>Welcome</h1>
<h4>Please login to enjoy our services</h4>
<form class=login-form name=login-form method=post>
<label for=username><span class=required>*</span>Username:</label>
<input id=username type=text name=username autofocus onkeyup=changeToUpperCase()>
<label for=password><span class=required>*</span>Password:</label>
<input type=password name=password size=8 maxlength=8>
<input class=login type=submit value=Login>
</form>
</div>
Here is the JavaScript:
function changeToUpperCase() {
document.login-form.value = document.login-form.value.toUpperCase();
}
This code does not work... and I have no idea how to remove spaces from an input text. Please help me.
More From » html