Jump to content

NodeList Index Javascript


Recommended Posts

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).

image.thumb.png.41526de57dde90bf68074424167b4334.png

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...