Javascript webpart retrieving textbox value too soon

Deanna Martens asked on November 23, 2015 18:57

I have a bizform with a custom form control on it that retrieves the employee name and store number based off of the employee number. In addition, I have a javascript that runs when the employee number has been changed. This javascript will go and get the textbox value and put that value in a regular bizform field.

The problem that I am having is that after a new employee number has been entered the javascript will go get the store number textbox value before it gets updated with the current employee's information.

$("#NewCoWorkerNumber input").change(function () { 
  var storeNumber = $(".StoreNumberForHiringStore").val();
  $("#HiringStore input").val(storeNumber);
});

Image Text

Recent Answers


Laura Frese answered on November 23, 2015 19:29

Try using set timeout to give the server a second or 2 to return the data

setTimeout(function(){ storeNumber = $(".StoreNumberForHiringStore").val(); }, 1500);
0 votesVote for this answer Mark as a Correct answer

Dawid Jachnik answered on November 24, 2015 09:20

Hello Deanna,

You can use focusout event of jquery instaed of change:

$("#NewCoWorkerNumber input").focusout(function () { 
    var storeNumber = $(".StoreNumberForHiringStore").val();
    $("#HiringStore input").val(storeNumber);
});
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.