Forum Moderators: open
function UrlString(init){ /* @annotation: Builds the url from any given form */
// var formElements = document.forms[0]; // Old method
var formElements = document.getElementById(init); // Dynamic method
for(var i = 0;i < formElements.length; i++){
if(formElements[i].value){ /* @annotation: Strips empty values */
urlvar += formElements[i].id + "=" + formElements[i].value + "&";
}
// else{
// urlvar += formElements[i].id + "=" + formElements[i].value + "&";
// }
}
urlvar = new String(urlvar);
urlvar = urlvar.replace(/undefined/g,"");
return urlvar;
}
When I call the function I have to define the form element.
var reports = "reports";
<body onload="callServer('/utils/reports.php', UrlString(reports), function(){ if(xmlHttp.readyState==4){if(xmlHttp.status==200){updateElement('reports_checkbox');}}});">
If I don't define the form I get an error. My question is why should "init" & init be theated differently. Thanks in advance.
fintan.
...UrlString(reports)...
Should read:
...UrlString('reports')... Then you wouldn't need to define your reports variable (var reports = "reports";)