2

I'm using ASP.NET, but on a certain page I am using regular html text boxes as the request is done with AJAX, rather than the traditional full page post back. My issue is that when the user fills out the last text box and presses enter the text box loses focus and the page scrolls all the way to the bottom.

I tried using the onblur event but it's not working, so I'm wondering what event is actually being called when the enter key is pressed(or any key for that matter).

I tried this:

$("#loginPass").blur(function (e) { if (e.keyCode == 13) $("#DealerLogin").click(); }); 

I have firebug for Firefox but can't figure out how to look at what js related operations are firing.

4
  • 3
    keydown, keypress, and keyup; in that order. Commented Feb 14, 2011 at 2:30
  • e is an event object, and should contain the full context of the event it represents, including what triggered it (source element, type of trigger, etc...). Should be able to inspect that with Firebug. Commented Feb 14, 2011 at 2:37
  • @JCOC611 if you press e.g. [Tab], things become more complicated. blurred input gets keydown and newly focused input gets keyup. Commented Feb 14, 2011 at 4:19
  • @Marc, your absolutely right, I wasn't thinking when I tried to use e.keyCode on a non key event. Commented Feb 14, 2011 at 22:11

3 Answers 3

5

In the Firebug scripts panel, you can click the pause button:

Pause btn in Firebug

Try it right before you hit enter, then step through the code.

Sign up to request clarification or add additional context in comments.

Comments

4

I wouldn't call myself a javascript expert, but this is what I would try.

When I get stuck, and don't know if or when my methods are being called , I fall back to using the trusty old "alert('in method 1');" technique to debug my code.

$(document).ready(function(){ alert("In document.ready()"); $("#loginPass").blur(function(e) { alert("In loginPass.blur() with keycode = " + e.keyCode); }); $("#loginPass").keydown(function(e) { alert("In loginPass.keydown() with keycode = " + e.keyCode); }); }); 

It certainly isn't an elegant technique, but is often revealing. If you find none of your methods are getting called, I guess make sure your text box id correctly matches "loginPass".

1 Comment

This often helps. The downside is, you may need to test in different browsers. And in some browsers event order may be even random.
0

My issue is that when the user fills out the last text box and presses enter the text box loses focus and the page scrolls all the way to the bottom.

Hmm. This is definitely not a default behaviour for browsers. You need to know, what does this and just catch this event or part of code.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.