-1

How can I execute a function only after a html element gets value ?

I've got an number input and a getJSON using its value as parameter, but the getJSON loads immediately with the initial value of the number, resulting in a null. How can I avoid that ?

Random User
  • 59
  • 11

1 Answers1

2

seems as if you are using some ajax call to get your desired number which is actually getting null. you actually want to make it sync

if yes then, go ahead and check out

Wait until all jQuery Ajax requests are done?

or else if you are using

xhttp.open("GET", "ajax_info.txt", true);

use this instead
xhttp.open("GET", "ajax_info.txt", false);

Reference : http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

Yati Sawhney
  • 1,372
  • 1
  • 12
  • 19