0

In Firefox, If I Tab on the controls in MVC View, then tab key is not working. it doesn't go to the next control.

function onlyAlphabets(e, t) {
        try {
            if (window.event) {
                var charCode = window.event.keyCode;
            }
            else if (e) {
                var charCode = e.which;
            }
            else { return true; }
            if (charCode == 9 || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
                return true;
            else
                return false;
        }
        catch (err) {
            alert(err.Description);
        }
    }
@Html.TextBoxFor(model => model.FirstName, new { @class = "form-control", @placeholder = "First Name", @id = "txtFirstName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" })
@Html.TextBoxFor(model => model.LastName, new { @class = "form-control", @placeholder = "Last Name", @id = "txtLastName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" })
matisetorm
  • 857
  • 8
  • 21
kkakadiya
  • 61
  • 8
  • does it work on any other browsers? Have you tried logging the charCode to make sure it's what you expect when you press the button (probably 9)? – ADyson Dec 12 '16 at 12:54
  • Yes, it is working in other browsers. I have put alert to capture charCode and it is displaying 0 instead 9, So it is going in else part. – kkakadiya Dec 12 '16 at 13:14
  • 1
    this might help http://stackoverflow.com/questions/4793233/capturing-the-tab-key-using-javascript-in-firefox – ADyson Dec 12 '16 at 13:20

1 Answers1

0

function onlyAlphabets(e, t) {
        try {
            if (window.event) {
                var charCode = window.event.keyCode;
            }
            else if (e) {
                var charCode = e.which;
            }
            else { return true; }
            if (charCode == 9 || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
                return true;
            else
                return false;
        }
        catch (err) {
            alert(err.Description);
        }
    }
@Html.EditorFor(model => model.FirstName, new { @class = "form-control", @placeholder = "First Name", @id = "txtFirstName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" })
@Html.EditorFor(model => model.LastName, new { @class = "form-control", @placeholder = "Last Name", @id = "txtLastName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" })