Onkeyup event JavaScript?

Best resource on DOM events: quirksmode.org/dom/events/keys.html.

Best resource on DOM events: quirksmode.org/dom/events/keys.html It looks like your event handler "search_buddy" fires an AJAX request, which is asynchronous. The rest of the function runs in parallel with the AJAX request, so "num" is undefined before the $. Post returns.

// num is undefined here... unless your network has 0 latency $("#Layer7"). Html(num); You need to wrap this code (pasted above) in a callback function. It appears to be parameter number 3: api.jquery.com/jQuery.post/ Untested, but best guess: function search_buddy() { $.

Post("num. Php", function (ret) { num=ret; $("#Layer7"). Html(num); }); } Here are some modifications to help you understand: function search_buddy() { alert("before the $.

Post execution"); $. Post("num. Php", function (ret) { num=ret; $("#Layer7").

Html(num); alert("$. Post callback"); }); alert("immediately after the $. Post execution"); } Note: "alert" will halt all JavaScript processing so you will be able to see what events occur when.

I read here webcheatsheet. Com/javascript/variables. Php that global variables do not need a "var" declaration,and hence I intended to declare num globally.

And why does the code work fine with two or more characters? – Anant Oct 8 '10 at 11:02 Your variable is implity global because you did not explicitly define it with "var". What this means is that your event handler is executing on the first event... you just don't see any output because you change the HTML before you get the ASYNC response.

Using my code should wrap the HTML changes in with the response code. – Oxyrubber Oct 8 '10 at 11:04 ^^I'm sorry I don't understand. How is the HTML changed before the response?

The code $("#Layer7"). Html(num); is after the $.post() function isn't it? – Anant Oct 8 '10 at 11:08 1 @Anant: the $.

Post function is handled in parallel with all of the rest of the Javascript adjacent to it. $. Post (1) makes an HTTP post to the server, (2) waits for the server response, (3) receives the response, and (4) runs the "callback" function (the one I wrote for you).

In your code, $("#Layer7"). Html(num); runs at the same time (1) is happening. If you move this code into the "callback" function, you are assured that it happens during (4) – Oxyrubber Oct 8 '10 at 11:26 1 In general, yes.

The difference is that $. Post internally makes an xmlhttprequest, then continues processing the rest of the JavaScript below the $. Post call.

When the response is returned, your callback function is executed soon after. This is similar to what happens with a setTimeout (I'll update my original response with an example). – Oxyrubber Oct 8 '10 at 11:32.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions