Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use key down event with Html text box helper in MVC4

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

@Html.TextBox("txtbx1", "", new {...} )
like image 853
Ell Avatar asked Mar 23 '23 02:03

Ell


2 Answers

You could do something like the following:

@Html.TextBox("txtbx1", "", new { onkeydown="MyFunction();" } )
like image 195
Jack Avatar answered Apr 09 '23 21:04

Jack


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; 
}
like image 45
Andréw Avatar answered Apr 09 '23 22:04

Andréw