Amaztulela Posted February 23, 2022 Report Share Posted February 23, 2022 I'm trying to get the NodeList Index number (i) using the below code to adjust the CSS depending on some parameters. There are several instances of the same DataPage on a single webpage with different filter parameters . NodeList looks like this showing 4 indexes (0, 1, 2, 3). The code always produces '4' for 'i' and not the correct NodeList index. 'Me' is updated correctly with the correct value matching with cbParamVirtual7.value. Can anyone help to point out where I'm going wrong? <script> var me = null; var issue= document.getElementById("cbParamVirtual7").value; var nlist = document.getElementsByName("cbParamVirtual7"); for (var i = 0; i < nlist.length; ++i) { if( isMe(nlist[i].value)){ me = nlist[i].value } }; function isMe(nlistElem){ return nlist[i].getAttribute('value') === issue; }; console.log(nlist); alert(nlist[i]); alert(nlist.length); alert(issue); alert(me); alert(i); </script> Quote Link to comment Share on other sites More sharing options...
Amaztulela Posted February 25, 2022 Author Report Share Posted February 25, 2022 Managed to solve the problem with the following code: <script> var me = null; var nlist= document.querySelectorAll("#cbParamVirtual7"); for (var i = 0; i < nlist.length; ++i) { if(isMe(nlist[i])){ me = nlist[i]; break; } }; function isMe(nlistElem){ return nlistElem.getAttribute('value') === '[@field:Issue_No]'; }; // script was added below to change CSS of different fields according to the NodeList Index [i]. //e.g. document.getElementsByName("EditRecordSubcategory")[i].readOnly= true; // document.getElementsByName("EditRecordCategory")[i].style.backgroundColor = '#F4F4F4'; //etc. </script> Kurumi 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.