Someone
Someone

Reputation: 10575

How do make the text in the TEXTBOX to Capital letter when the user starts typing text in jquery

when the user starts typing the text in to the text box we need to make those letters to capital letters

Upvotes: 4

Views: 8059

Answers (4)

RahulOnRails
RahulOnRails

Reputation: 6542

Just add text-transform: uppercase to your styling, and then on the server side you can convert it to uppercase.

input {
  text-transform: uppercase;
}

Upvotes: 3

Ender
Ender

Reputation: 15221

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.

Upvotes: 2

chigley
chigley

Reputation: 2592

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!

Upvotes: 8

user372551
user372551

Reputation:

$(function() {
  $('input[type=text]').bind('keyup', function() {
    var val = $(this).val().toUpperCase()
    $(this).val(val);
  });
});

Test it here :http://jsbin.com/opobu3

Upvotes: 2

Related Questions