when the user starts typing th开发者_StackOverflowe text in to the text box we need to make those letters to capital letters
Instead of a jQuery solution, I'd be tempted to use CSS to make the text inside the input to appear to be capitals (text-transform: uppercase
), regardless of whether or not they were inputted as lower or upper case. Then when you process your data, convert the data to upper case. For example in PHP, you'd use strtoupper()
- there are equivalent functions in most other languages I imagine you might be processing the form with!
EDIT: See chigley's answer instead.
$(function() {
$('#myTextBox').keyup(function() {
$(this).val($(this).val().toUpperCase());
});
});
Demo: http://jsfiddle.net/SMrMQ/
Alternately, style with CSS and do actual conversion on your back-end.
$(function() {
$('input[type=text]').bind('keyup', function() {
var val = $(this).val().toUpperCase()
$(this).val(val);
});
});
Test it here :http://jsbin.com/opobu3
Just add text-transform: uppercase to your styling, and then on the server side you can convert it to uppercase.
input {
text-transform: uppercase;
}
精彩评论