Mushigee2266 Posted July 25, 2022 Report Share Posted July 25, 2022 I have 6 virtual fields from RD1 to RD6 I want that when user select "MIANT" from WorkOut filed" the label RD2 to RD6 changes to NA Can any body help me. Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted July 25, 2022 Report Share Posted July 25, 2022 Hello @Mushigee2266, If only these 6 fields are Virtual fields, you may test this code in the DataPage Footer. Do not forget to disable the HTML editor on the Advanced tab before pasting the code. <script> document.addEventListener('DataPageReady', assignEventListeners); function assignEventListeners() { document.querySelector('#InsertRecordWorkOut').addEventListener('change', labelChangeHandler); // douple-check the field name document.removeEventListener('DataPageReady', assignEventListeners) }; function labelChangeHandler(event) { const dropdownValue = event.target.value; const labelsArr = document.querySelectorAll('[for^="cbParamVirtual"]:not([for="cbParamVirtual1"])'); if(dropdownValue == 'MIANT'){ labelsArr.forEach(label =>{ label.innerText = 'NA'; }); } else{ labelsArr.forEach((label, index) =>{ label.innerText = `RD${index+2}`; }); } }; </script> Quote Link to comment Share on other sites More sharing options...
Mushigee2266 Posted July 26, 2022 Author Report Share Posted July 26, 2022 Thanks for your effort. This code is not working. I have more 22 virtual fields . But i want to change RD2 to RD6 (I want to change cbVirtual1 to MAINT and cbVirtual2,cbVirtual3,cbVirtual4,cbVirtual5 to NA. Field Name Label cbParamVirtual2 RD2 cbParamVirtual3 RD3 cbParamVirtual4 RD4 cbParamVirtual2 RD5 Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted July 26, 2022 Report Share Posted July 26, 2022 @Mushigee2266, If you have more Virtual fields, please test this code: <script> document.addEventListener('DataPageReady', assignEventListeners); function assignEventListeners() { document.querySelector('#InsertRecordWorkOut').addEventListener('change', labelChangeHandler); //double-check the field name, it is WorkOut in the example document.removeEventListener('DataPageReady', assignEventListeners) }; function labelChangeHandler(event) { const dropdownValue = event.target.value; const labelsArr = document.querySelectorAll('[for="cbParamVirtual2"], [for="cbParamVirtual3"], [for="cbParamVirtual4"], [for="cbParamVirtual5"],[for="cbParamVirtual6"]'); //double-check the field names, they are from Virtual 2 to Virtual 6 in the example if(dropdownValue == 'MIANT'){ labelsArr.forEach(label =>{ label.innerText = 'NA'; }); } else{ labelsArr.forEach((label, index) =>{ label.innerText = `RD${index+2}`; }); } }; </script> The code works for me. For example, I select the "A" value, the labels are RD 1- RD 6 When I select the "MIANT" value, the labels are changed: Hope this works for you as well. Quote Link to comment Share on other sites More sharing options...
Mushigee2266 Posted July 26, 2022 Author Report Share Posted July 26, 2022 Thanks for your effort. This code is not working. I have more 22 virtual fields . But i want to change RD2 to RD6 (I want to change cbVirtual1 to MAINT and cbVirtual2,cbVirtual3,cbVirtual4,cbVirtual5 to NA. Field Name Label cbParamVirtual2 RD2 cbParamVirtual3 RD3 cbParamVirtual4 RD4 cbParamVirtual2 RD5 Quote Link to comment Share on other sites More sharing options...
Mushigee2266 Posted July 26, 2022 Author Report Share Posted July 26, 2022 Thank you very much code is working now only mistake was WORKOUT case. I have made switch statement by getting idea from this both are working your code and switch statement. Thanks a lot for your cooperation and support here is my code <script> document.addEventListener('DataPageReady', assignEventListeners); function assignEventListeners() { document.querySelector('#InsertRecordWORKOUT').addEventListener('change', labelChangeHandler); // douple-check the field name document.removeEventListener('DataPageReady', assignEventListeners) }; function labelChangeHandler(event) { const dropdownValue = event.target.value; var textWO = document.getElementById('InsertRecordWORKOUT'); const labelsArr = document.querySelectorAll('[for="cbParamVirtual1"],[for="cbParamVirtual2"],[for="cbParamVirtual3"],[for="cbParamVirtual4"],[for="cbParamVirtual5"],[for="cbParamVirtual6"]'); switch(dropdownValue) { case 'MAINT': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'MAINT2': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'MiNUTES': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'STREN': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'STREN2': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'FJB': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'ROWPLANK': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case 'TiMeWaRp': labelsArr[0].innerText=textWO.value; labelsArr[1].innerText='NA'; labelsArr[2].innerText='NA'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; case '3HUNDRED': labelsArr[0].innerText='PUSH UPS'; labelsArr[1].innerText='SIT UPS'; labelsArr[2].innerText='NVRSRRNDR'; labelsArr[3].innerText='NA'; labelsArr[4].innerText='NA'; labelsArr[5].innerText='NA'; Break; default: labelsArr[0].innerText='RD1'; labelsArr[1].innerText='RD2'; labelsArr[2].innerText='RD3'; labelsArr[3].innerText='RD4'; labelsArr[4].innerText='RD5'; labelsArr[5].innerText='RD6'; } }; </script> 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.