Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change to uppercase w/ mouse paste 1

Status
Not open for further replies.

Thinius

Programmer
Oct 27, 2010
8
GB
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?

Code:
<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>
 
There is such a thing as an onPaste event. However it is less than fully supported. FF,IE and Safari seem to support it. Though the event fires before the textbox is actually populated by the pasted text. Dabbing a bit, I managed to get this work correctly with a setTimeout.



Code:
<script>
function UpperCase(){
var box=document.getElementById('mytxt');
box.value=box.value.toUpperCase();
}
</script>

Copy and Paste:
<input type=text name="mytxt" id="mytxt" onpaste="setTimeout('UpperCase();',150);">




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks Vacunita, you're right about the browers but its still a great help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top