...

View Full Version : How do I change to uppercase w/ mouse paste too?



Thinius
11-14-2010, 08:45 AM
Hi everyone, I've been trying to amend this so that when I paste text in with a mouse it changes to uppercase automatically. Does anyone know how this can be done?



<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value=y.toUpperCase();
}
</script>
</head>

<body>
Enter your name: <input type="text" id="fname" onchange="upperCase(this.id)" />
</body>

</html>


Thanks

Philip M
11-14-2010, 10:25 AM
onkeyup = "upperCase(this.id)" onblur="upperCase(this.id)"

But all upper-case does not look too good. Why not format the name with the usual capitals and lower case?


var str1 = "jEAn-paul o'flaNAGan-macDONald"
str1 = str1.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});
alert(str1); // Jean-Paul O'Flanagan-Macdonald



All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

glenngv
11-14-2010, 10:56 AM
Thinius, you're going around by passing this.id then in the function you get the object reference of that id when you already have the object reference and can simply pass this.


function upperCase(obj)
{
obj.value = obj.toUpperCase();
}
...
<input type="text" id="fname" onkeyup="upperCase(this);" onblur="upperCase(this);" />

mrhoo
11-14-2010, 03:55 PM
// never mind, answered

glenngv
11-15-2010, 12:03 AM
Actually, you can capitalize it even without javascript by using CSS text-transform property.


Enter your name: <input type="text" id="fname" style="text-transform:uppercase;" />

This will uppercase the input on the display only. Internally, it's still not uppercased, so if you want to also make it uppercase when you process it on client-side or server-side, you should uppercase it accordingly.

Philip M
11-15-2010, 09:34 AM
Actually, you can capitalize it even without javascript by using CSS text-transform property.


Enter your name: <input type="text" id="fname" style="text-transform:uppercase;" />

This will uppercase the input on the display only. Internally, it's still not uppercased, so if you want to also make it uppercase when you process it on client-side or server-side, you should uppercase it accordingly.

With respect, that makes it useless. :p In any case, as I say, all upper-case does not look too good (SHOUTING!). Why not format the name with the usual capitals and lower case?

glenngv
11-15-2010, 10:27 AM
We don't know why the OP wants it all uppercase. He/she may have a good reason to do that. In any case, I still prefer the CSS solution as I think the main reason why you want a text to be uppercased is for display purposes. I don't think it really matters if what is stored on the backend is uppercased or not.

And to capitalize only the first letter, you just need to set text-transform to capitalize.

<input type="text" id="fname" style="text-transform:capitalize;" />

Philip M
11-15-2010, 07:03 PM
We don't know why the OP wants it all uppercase. He/she may have a good reason to do that. In any case, I still prefer the CSS solution as I think the main reason why you want a text to be uppercased is for display purposes. I don't think it really matters if what is stored on the backend is uppercased or not.

And to capitalize only the first letter, you just need to set text-transform to capitalize.

<input type="text" id="fname" style="text-transform:capitalize;" />

Does not work with O'Flanagan (O'flanagan). :p

For the rest, we will have to agree to disagree. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum