Currently, I am working on a project that involves editing multiple elements within a window simultaneously using AJAX. My goal is to have all "open for editing" elements saved when the user clicks the save button for the entire window.
However, I encountered an issue where an anchor tag was used around images instead of onclick functions, forcing me to use the eval
function to call the necessary actions.
Here is the code snippet I am using for the window-wide save button:
var as = document.getElementsByClassName('link_salvare');
alert(as.length);
for(var i = 0; i < as.length; i++) {
alert(i);
eval(as[i].href);
}
alert('finished');
After testing, I discovered that the 'for' loop stops after the first iteration (i=0) even though there are two editing elements present. Whether using asynchronous or synchronous AJAX calls, I still cannot get all elements saved.
While I could potentially resolve this by allowing only one element to be edited at a time, I need approval to make changes to individual save functions post-weekend.
For now, I managed to work around this issue by:
a) Converting from
<a href="javascript:function"><img>
to <img onclick="function">
to avoid using eval;
b) Adjusting the window layout so that only one element can be edited at any given moment.
Although the core problem remains unresolved, these workarounds ensure smooth functionality until further investigation can be done.