Reputation: 501
I'm developing a few forms for my company to use. I consult and insert data into the database, but for standard issues I want to transform the text I enter to uppercase, How I do that?
Example of one of my forms:
I want the text fields I enter in automatically transformed to uppercase, or the data that I enter into my database already transformed to uppercase (in the case that the user doesn't enter it that way).
EDIT:
I try
$("tbCiudad").change(function() {
$(this).val($(this).val().toUpperCase());
});
or
$("tbCiudad").keyup(function() {
$(this).val($(this).val().toUpperCase());
});
and nothing happens to that field. What am I doing wrong?
Upvotes: 13
Views: 53954
Reputation: 1964
Use this Function
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("#text_field_id").keyup(function() {
$(this).val($(this).val().toUpperCase());
});
});
</script>
Upvotes: 1
Reputation: 5954
You can use the javacsript method toUpperCase()
for this conversion.
Upvotes: 1
Reputation: 3323
$("input[type=text]").keyup(function(){
$(this).val( $(this).val().toUpperCase() );
});
Upvotes: 28
Reputation: 6654
Do you want to save it or only show it in UPPERCASE?
If you need only to show, you can you CSS:
<style type="text/css">
input {
text-transform:uppercase;
}
</style>
If you want to save it in uppercase, the server-side is the best way to do it. I suggest creating a custom ModelBinder that would call String.ToUpper on every string property.
You can also mix both of this strategies.
Upvotes: 1
Reputation: 18064
Just apply CSS class to all required fields:-
.uppercase
{
text-transform: uppercase;
}
Refer CSS text-transform Property
Upvotes: 0
Reputation: 9092
You can add an event handler with javascript (or jquery if you want) to keypress
or blur
events of those textboxes and then apply what Jay Blanchard suggested. Something like this:
$("input[type='text']").bind("blur", null, function(e) {
$(this).val($(this).val().toUpperCase());
});
Upvotes: 5
Reputation: 1200
Use javascript toUpperCase method.
I am also sure there is a function in ASP to do that such as strtoupper in PHP
Upvotes: 0