fix: Update JavaScript functions#33
Conversation
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| document.onclick=function(event){ | ||
| if(document.getElementById('servicelist').style.display=="block"){ | ||
| hideItem('servicelist'); | ||
| } | ||
| }; |
There was a problem hiding this comment.
document.onclick assumes #servicelist always exists; on pages where the menu isn’t rendered (e.g., logged-out views), getElementById('servicelist') is null and .style will throw, breaking all click handling. Add a null-check (or early return) before reading .style.display (and ideally only register the handler when the element exists).
| document.onclick=function(event){ | |
| if(document.getElementById('servicelist').style.display=="block"){ | |
| hideItem('servicelist'); | |
| } | |
| }; | |
| var servicelist = document.getElementById('servicelist'); | |
| if (servicelist) { | |
| document.onclick=function(event){ | |
| if(servicelist.style.display=="block"){ | |
| hideItem('servicelist'); | |
| } | |
| }; | |
| } |
| oEvent = window.event; // IE | ||
| } | ||
| if (msg && test_values_set()) { | ||
| oEvent.returnValue = msg; |
There was a problem hiding this comment.
window.onbeforeunload handler sets oEvent.returnValue but never returns the message. Some browsers only show the confirmation prompt when the handler returns a non-empty string; return msg when test_values_set() is true.
| oEvent.returnValue = msg; | |
| oEvent.returnValue = msg; | |
| return msg; |
| for (i=0,n=theForm.elements.length;i<n;i++) | ||
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | ||
| name = theForm.elements[i].name; | ||
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | ||
| ids = name.substring( name.lastIndexOf( "." )+1 ); |
There was a problem hiding this comment.
This loop assigns to i, n, name, id, and ids without declarations, creating/overwriting globals (e.g., window.name) and risking cross-function interference. Declare these variables locally (e.g., var/let) inside deleteArticle.
| for (i=0,n=theForm.elements.length;i<n;i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| name = theForm.elements[i].name; | |
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| ids = name.substring( name.lastIndexOf( "." )+1 ); | |
| for (var i=0, n=theForm.elements.length; i<n; i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| var name = theForm.elements[i].name; | |
| var id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| var ids = name.substring( name.lastIndexOf( "." )+1 ); |
| for (i=0,n=theForm.elements.length;i<n;i++) | ||
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | ||
| name = theForm.elements[i].name; | ||
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | ||
| ids = name.substring( name.lastIndexOf( "." )+1 ); | ||
| getResponse( page + "?id=" + ids, id ); | ||
| } |
There was a problem hiding this comment.
This loop assigns to i, n, name, id, and ids without declarations, creating/overwriting globals and risking cross-function interference. Declare these variables locally inside deleteArticleAdmin.
| for (i=0,n=theForm.elements.length;i<n;i++) | ||
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | ||
| name = theForm.elements[i].name; | ||
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | ||
| ids = name.substring( name.lastIndexOf( "." )+1 ); |
There was a problem hiding this comment.
This loop assigns to i, n, name, id, and ids without declarations, creating/overwriting globals and risking cross-function interference. Declare these variables locally inside deleteCategory.
| for (i=0,n=theForm.elements.length;i<n;i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| name = theForm.elements[i].name; | |
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| ids = name.substring( name.lastIndexOf( "." )+1 ); | |
| for (var i=0, n=theForm.elements.length; i<n; i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| var name = theForm.elements[i].name; | |
| var id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| var ids = name.substring( name.lastIndexOf( "." )+1 ); |
| for (i=0,n=theForm.elements.length;i<n;i++) | ||
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | ||
| name = theForm.elements[i].name; | ||
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | ||
| ids = name.substring( name.lastIndexOf( "." )+1 ); |
There was a problem hiding this comment.
This loop assigns to i, n, name, id, and ids without declarations, creating/overwriting globals and risking cross-function interference. Declare these variables locally inside deleteSale.
| for (i=0,n=theForm.elements.length;i<n;i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| name = theForm.elements[i].name; | |
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| ids = name.substring( name.lastIndexOf( "." )+1 ); | |
| for (var i=0, n=theForm.elements.length; i<n; i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| var name = theForm.elements[i].name; | |
| var id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| var ids = name.substring( name.lastIndexOf( "." )+1 ); |
| for (i=0,n=theForm.elements.length;i<n;i++) | ||
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | ||
| name = theForm.elements[i].name; | ||
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | ||
| ids = name.substring( name.lastIndexOf( "." )+1 ); |
There was a problem hiding this comment.
This loop assigns to i, n, name, id, and ids without declarations, creating/overwriting globals and risking cross-function interference. Declare these variables locally inside deleteUser.
| for (i=0,n=theForm.elements.length;i<n;i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| name = theForm.elements[i].name; | |
| id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| ids = name.substring( name.lastIndexOf( "." )+1 ); | |
| for (var i=0, n=theForm.elements.length; i<n; i++) | |
| if (theForm.elements[i].name.indexOf('COLLECTION_SELECTION_') !=-1 && theForm.elements[i].checked == true){ | |
| var name = theForm.elements[i].name; | |
| var id = name.substring( name.lastIndexOf( "_" )+1, name.lastIndexOf( "." ) ); | |
| var ids = name.substring( name.lastIndexOf( "." )+1 ); |
Automated fix by CoderOps.
Swarm: swarm50
Task: Update JavaScript functions