0

This is my HTML:

<html>
<head>
<script>
function ppid() {
    var ppidtxt = document.getElementById('ppid').value;
    var newppidtxt = ppidtxt.toUpperCase();
    var ppide = document.getElementById('ppid');
    ppide.value = newppidtxt;
}
</script>
</head>
<body>
<form>
  <center><input type="text" id="ppid" class="form-control" name="ppid" placeholder="Personal Project ID" onchange="ppid();" /></center>
</form>
</body>
</html>

I've tried this is JSFiddle, on my local PC, pretty much everywhere but for some reason, whenever I type something in the form's text box with the id "ppid" it isn't capitalizing it. What have I done wrong?

4

2 Answers 2

0

Try using onkeyup instead, e.g.

<input type="text" onkeyup="this.value=this.value.toUpperCase()" />
Sign up to request clarification or add additional context in comments.

1 Comment

This worked. You're definitely a JavaScript life-saver.
0

I don't know why this happens, but when onchange is called, 'ppid' contains the HTMLInputElement (probably because of its id).

If you rename the function to something unique (like 'myFunc') it works.

@MelanciaUK brought the answer with this link: Why JS function name conflicts with element ID?

2 Comments

I wouldn't know about this if I didn't spot this question. Never been through this kind of issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.