I have a simple function that does nothing:
function doNothing(){}
I also have a function that looks like this:
function getJson() {
var JSONObject = {
"name": "John Johnson",
"street": "Oslo West 555",
"age": 33,
"phone": "5551234var stuff = <%= @var %>;567"
};
document.getElementById("name").value = JSONObject.name;
setTimeout(doNothing(), 1000);
document.getElementById("street").value = JSONObject.street;
So the doNothing() function is actually here only so I can put a parameter in the setTimeout function.
The point of the whole javascript code is that i want the first value to be shown immediatly and the second one after 1 second (1000miliseconds), but it never shows up.
Can someone please tell me what am I doing wrong?
The settimeout is not a sleep function, it will take a function and call it after 1000 milliseconds. Your other code will still execute right away.
Try: