Arthik Arthik - 1 year ago 77
Javascript Question

The value not changed in the keydown event

I have the following function:

formCreated = function (event, data) {
console.log(data.formType); // output: 'edit'

$('body').on('keydown', function (e) {
if (e.ctrlKey && e.which == 80) {

if (data.formType == 'create') // not changed until page refresh
alert('save the record');
else if (data.formType == 'edit')

After saving record the
changed as 'edit', but inside the event value not changed until page refresh.

Answer Source


$('body').off('keydown').on('keydown', function (e) {
   // your code here

The .off() method removes registered values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download