Q: Onload not working: Uncaught reference error, function not defined I'm getting the above error using this code example in C, the functions used is in src.js. When I load the webui, the error pops up for someFunction() but anotherFunction() works just fine:
fprintf(out, "<script type='text/javascript' src='/src.js'></script>\n"); 
fprintf(out, "<body onload=\"someFunction()\">\n");
fprintf(out, "<button type='button' id='CheckButton' onclick='anotherFunction()'>Check</button></br>");

src.js:
var check = 0;
function someFunction()
{
    req=new XMLHttpRequest();
    req.onreadystatechange=yetAnotherFunction;
    req.open("GET","xxx",true);
    req.send();
    setTimeout("someFunction()", 3000);
}

function anotherFunction()
{
  if (!check) {
    check = 1;
    setButtonText('CheckButton', 'Stop Checking');
    someFunction();
  } else {
    check = 0;
    setButtonText('CheckButton', 'Checking');
  }
}

What I'm trying to do is remove the button and replace it with the onload feature. Does anyone know what's wrong with this code?

A: In javascript, function is a keyword which is used to create functions. It cannot be used as name of any function.
In your src.js, change someFunction to 
function someFunction() {

  console.log("someFunction")
  req = new XMLHttpRequest();
  req.onreadystatechange = yetAnotherFunction;
  req.open("GET", "xxx", true);
  req.send();
  setTimeout(someFunction, 3000);  // <== this is wrong
}

to call it as fprintf(out, "<body onload=\"someFunction()\">\n");
In someFunction(), you must pass a function as a parameter to setTimeout, not a string.
