Forum Moderators: open

Message Too Old, No Replies

Problem with getElementById(init) & getElementById("init")

         

fintan

2:33 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Hi I have a function to parse all the elements from a form and create a url from them.

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.

penders

3:23 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure if I have quite understood your question, but my guess is that you have simply missed some ' (single quotes) in the call to your UrlString() function.

...UrlString(reports)...

Should read:

...UrlString('reports')...

Then you wouldn't need to define your reports variable (var reports = "reports";)

fintan

3:48 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Thank for the reply penders

I was trying that earlier but it didn't work. Seems to be working now. Thanks

pixeltierra

4:27 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



reports is a var
'reports' is a string

you need to send the string or send a var that = the string