Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change all input values to uppercase using Jquery?

I want to change all my form values to uppercase before the form is submitted.

So far I have this but it's not working.

$('#id-submit').click(function () {
        var allInputs = $(":input");
        $(allInputs).value.toUpperCase();
        alert(allInputs);
});
like image 542
Gustavo Reyes Avatar asked Mar 01 '13 17:03

Gustavo Reyes


People also ask

How do you change input value to uppercase?

Use toLocaleUpperCase() method to transform the input to uppercase and again set it to the input element.

How do you capitalize input in JavaScript?

The toUpperCase() method converts a string to uppercase letters. The toUpperCase() method does not change the original string.


2 Answers

Try like below,

$('input[type=text]').val (function () {     return this.value.toUpperCase(); }) 

You should use input[type=text] instead of :input or input as I believe your intention are to operate on textbox only.

like image 95
Selvakumar Arumugam Avatar answered Sep 16 '22 15:09

Selvakumar Arumugam


use css :

input.upper { text-transform: uppercase; }

probably best to use the style, and convert serverside. There's also a jQuery plugin to force uppercase: http://plugins.jquery.com/plugin-tags/uppercase

like image 22
Amrendra Avatar answered Sep 17 '22 15:09

Amrendra