In short, I want to use an object literal to allow me to pass a unknown amount of variables in any order to a function. Whilst this is not big deal in theory, in my code, this object literal is passed to a second function called on_change
.
on_change
works by comparing an element's innerHTML to a string; If it is the same, it sets a timeout to call the function again. If the element's innerHTML is different from the string, then the third parameter is executed, this will either be a function or a string. either way it will execute. I have tested this function plenty and used it for a while now.
However, I cannot seem to get the object literal to flow through the function calls...
var params = { xpos:'false'};
on_change('window_3_cont_buffer','','
if(Window_manager.windows[3].window_cont_buffer.getElementsByTagName(\'content\')[0].getElementsByTagName(\'p\')[0].innerHTML == \'ERROR\'){
alert(Window_manager.windows[3].window_cont_buffer.getElementsByTagName(\'content\')[0].getElementsByTagName(\'p\')[1].innerHTML);
return false;
} else {
Window_manager.windows[3].load_xml(\'location/view.php?location_ID=3\', \'\', ' + params + ' ); }
');
I call this as part of the form submission. After this line, I then call a function to load some content via ajax, which works fine and will trigger the code from the on_change
function.
I have tested the load_xml
function, it is able to call alert(param.xpos)
and get the correct response. I can even added in a check for being undefined so that rest of the times I call load_xml
I don't get swamped with alerts.
The load_xml
function first sets up the on_change
function, then calls the function to load the content to a hidden div. Once the AJAX request has updated that DIV, the on_change
function should now call the parse_xml
function. This pulls out the information from the xml file. However... The idea of this object literal param is that it can tell this parse_xml
function to ignore certain things.
on_change("window_" + this.id + "_cont_buffer", "", "Window_manager.windows[" + this.id + "].parse_xml('" + param + "')");
This is part of load_xml
, it works perfectly fine, even with the param bit in there. except, parse_xml
does not seem to be able to use that parameter.
I have been able to get it to a point where parse_xml
can alert(param)
and give [object object]
which I would of thought meant that the object literal had been passed through, but when I try and call alert(param.xpos)
I get undefined.
I know this is a pig of a problem, and I could get around it by just having the function take a zillion boolean parameters, but its just not a very nice solution.