How to Automatically Set Text Box to Uppercase

How do you automatically set text box to Uppercase?

You've put the style attribute on the <img> tag, instead of the <input>.

It is also not a good idea to have the spaces between the attribute name and the value...

<input type="text" class="normal" 
name="Name" size="20" maxlength="20"
style="text-transform:uppercase" />
<img src="../images/tickmark.gif" border="0" />

Please note this transformation is purely visual, and does not change the text that is sent in POST.

NOTE: If you want to set the actual input value to uppercase and ensure that the text submitted by the form is in uppercase, you can use the following code:

<input oninput="this.value = this.value.toUpperCase()" />

how do i set property of text box to UpperCase

The best method would be to change the styling on your form to display uppercase:

input.normal
{
text-transform:uppercase;
}

SEE EXAMPLE


However this will not actually convert the string to uppercase, just style it to appear this way.

Therefore then when the data is submitted, use whatever server side language to convert the string to uppercase for purposes of storing in the database etc. For example with .NET you would do:

str.ToUpper();

Change Input to Upper Case

I think the most elegant way is without any javascript but with css. You can use text-transform: uppercase (this is inline just for the idea):

<input id="yourid" style="text-transform: uppercase" type="text" />

Edit:

So, in your case, if you want keywords to be uppercase change:
keywords: $(".keywords").val(), to $(".keywords").val().toUpperCase(),

How to change the input to uppercase as it is being typed

How about CSS:

input.upper { text-transform: uppercase; }

Remark: This will still send the value to the server as typed by the user and not uppercased.

TextBox only in uppercase

Unfortunately, there is no better way than tracking TextChanged. However, your implementation is flawed because it doesn't account for the fact that the user might change the caret position.

Instead, you should use this:

private void TextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
TextBox currentContainer = ((TextBox)sender);
int caretPosition = currentContainer.SelectionStart;

currentContainer.Text = currentContainer.Text.ToUpper();
currentContainer.SelectionStart = caretPosition++;
}

Typescript + Html: How to force uppercase in an input field

You can simply add oninput="this.value = this.value.toUpperCase()" in your <input> tag and it will instantly convert any input in your input field to Uppercase.



Related Topics



Leave a reply



Submit