Hemanth Aitharaju
Hemanth Aitharaju

Reputation: 17

KeyUp event with Html.TextBoxFor

I need help in using keyup with @Html.TextBoxFor. I have a html code which creates a new row of texboxes on each button click. Now i want to convert the text entered into that textbox into upper case while the user enters. Thought of using OnKeyUp event, but need help in syntax with @Html.TextBoxFor . I'm new to .Net. Here's my html code line

<div>@Html.TextBoxFor(x =>x.ItemName[0].SerialNumber, new {autocomplete = "off"}) </div>

Help me with the JS also please

Upvotes: 1

Views: 3161

Answers (1)

Selim Yildiz
Selim Yildiz

Reputation: 5370

You can add OnKeyUp attribute to your textbox:

@Html.TextBoxFor(x =>x.ItemName[0].SerialNumber, new {autocomplete = "off", onkeyup="ToUpper(this);"})

On the script side, you need to have ToUpper method also like this:

<script>
    function ToUpper(obj)
    {
        if (obj.value!="")
        {
            obj.value = obj.value.toUpperCase();
        }
    }
</script>

Upvotes: 1

Related Questions