Using ‘keyup’ vs ‘keydown’ on jQuery .val() for HTML elements

So I had a code that looked like this

 

$('#invoice_details').on('keydown','#item_amount',function(){

 var qty = $(this).parent().prev().children('#item_qty').val();
 var amt = $(this).val();
 console.log(qty);

 //Do the Math
 var total = (qty * amt);

 $('#item_total').val(total);

})

 

Because of using keydown, jQuery doesn’t have time to tell what the input is until after you essentially “enter” the command from the keyboard aka “pulling your finger up off the key”. Once the keyboard sends the data, then jQuery can see the value. This is why you need to use ‘keyup’. Jquery waits for the keyup event to happen on your keyboard and then sends the results to the .val() function. Good thing to know :)

 

It should look like this:

 

$('#invoice_details').on('keyup','#item_amount',function(){

 var qty = $(this).parent().prev().children('#item_qty').val();
 var amt = $(this).val();
 console.log(qty);

 //Do the Math
 var total = (qty * amt);

 $('#item_total').val(total);

})

Great Experiment on Internet Lag

Lag drives me nuts. Especially when I’m playing a video game and I have to wait. it’s the worst on racing games. Im always running into the wall thanks to lag. This is a great experiment using Raspberry Pi & the Oculus¬†Rift

 

 

One of my all time favorite jokes

A man wakes up at home with a huge hangover. He forces himself to open his eyes, and the first thing he sees is a couple of aspirins and a glass of water on the side table.

He sits up and sees his clothing in front of him, all clean and pressed. He looks around the room and sees that it is in perfect order, spotless, clean.

So is the rest of the house. He takes the aspirins and notices a note on the table: “Darling, breakfast is on the stove, I left early to go shopping. Love you.” So he goes to the kitchen, and sure enough there is a hot breakfast and the morning newspaper.

His son is also at the table, eating. He asks, “Son, what happened last night?”

His son says, “Well, you came home after 3 A.M., drunk and delirious, broke some furniture, puked in the hallway, and gave yourself a black eye when you stumbled into the door.”

Confused, He asks, “So, why is everything in order and so clean, and breakfast is on the table waiting for me?”

His son replies, “Oh, that! Mom dragged you to the bedroom, and when she tried to take your pants off, you said, “Lady, leave me alone, I’m married!!!”