4

How do you add a key down event with this text box?

@Html.TextBox("txtbx1", "", new {...} )
Alicia
  • 1,152
  • 1
  • 23
  • 41
Ell
  • 83
  • 1
  • 1
  • 7

2 Answers2

6

You could do something like the following:

@Html.TextBox("txtbx1", "", new { onkeydown="MyFunction();" } )
Jack
  • 9,156
  • 4
  • 50
  • 75
1

Try it like this.

Call:

@Html.TextBoxFor(model => model.BoardSizeX, new { @onkeydown = "return Foo(event, $(this).val());"})

Function:

 function foo(event, currentValue) {
       console.log(event);
       console.log(currentValue);

       return true; 
}
Andréw
  • 96
  • 1
  • 11