To put it simply, my goal is to utilize an object literal that allows me to pass an unknown quantity of variables in any order to a function. While this may seem straightforward in principle, within my code, this object literal is passed to a second function named on_change
.
on_change
essentially operates by comparing the innerHTML of an element to a string; if they match, a timeout is set to trigger the function again. If the innerHTML differs from the string, the third parameter is executed, which could be either a function or a string - either way, it executes. I've thoroughly tested and used this function for some time now.
Yet, I'm encountering difficulties in getting the object literal to smoothly progress 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 invoke this as part of the form submission process. Subsequently, I call a function to load content via AJAX, which functions correctly and triggers the on_change
function as intended.
I have verified that the load_xml
function can successfully execute alert(param.xpos)
and receive the correct response. Furthermore, I've included a check for undefined values to prevent excessive alerts when calling load_xml
subsequently.
The load_xml
function first configures the on_change
function, then proceeds to load the content into a hidden div. Once the AJAX request updates that DIV, the on_change
function should activate the parse_xml
function. This function is designed to extract information from the XML file. However... The purpose of using this object literal param is to instruct the parse_xml
function to disregard certain elements.
on_change("window_" + this.id + "_cont_buffer", "", "Window_manager.windows[" + this.id + "].parse_xml('" + param + "')");
Within the context of load_xml
, everything works flawlessly, even with the inclusion of the param segment. Nevertheless, the issue arises when parse_xml
seemingly fails to utilize that parameter.
I managed to reach a point where parse_xml
can effectively alert(param)
and provide "[object object]", indicating that the object literal was indeed passed through. However, upon trying to execute alert(param.xpos)
, I only receive 'undefined'.
Admittedly, this presents quite a challenge, and while I could circumvent it by incorporating numerous boolean parameters within the function, it's not the most elegant solution.