anyalynn Posted May 7, 2021 Report Share Posted May 7, 2021 I have a script that works in my unpublished test application: <script> document.addEventListener('BeforeFormSubmit', function(event) { let checkValue = document.querySelector("select[id*='InsertRecordUWRadio']").value; if (checkValue == 'Yes') { let npiValue = document.querySelector("input[id*='InsertRecordNewNPI']").value; document.querySelector("input[id*='InsertRecordOrigNPI']").value=npiValue; } }); </script> UWRadio is a text field where I use a custom dropdown type with values "Yes" and "No" . NewNPI is a calculated field and OrigNPI is a required field that if the UWRadio is "No" must be filled in by the user. Then I put it in my real published application (field names are different), and it doesn't work. It will not get the values from the select list. <script> document.addEventListener('BeforeFormSubmit', function(event) { if (event.detail.appKey == 'xxxxxx') { //get the unique id for DOM element var elementID = event.detail.uniqueSuffix; let checkValue = document.querySelector("select[id*='InsertRecordCurrentUWStudent']").value; if (checkValue == 'Yes') { let npiValue = document.querySelector("input[id*='InsertRecordUWStudentNPI+elementID']").value; document.querySelector("input[id*='InsertRecordNPI']").value=npiValue; } } }); </script> When I look at the source, sometimes the ids have the elementID and sometimes not. It is all very confusing. Hopefully, I'm making a simple mistake. Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted May 7, 2021 Report Share Posted May 7, 2021 what do you mean element ID? How are you testing this script? Take note that there is a temporary APPKey for DataPage when you use Preview, the AppKey in its properties is the real appkey when the DataPage is accessed through any deployment method, if that's what you're using, the script will not work in the preview. To get the temporary AppKey, just click preview and copy the value at the end of the URL, do not close this preview, as it will change if you closed it and preview it again. Just to add, don't need this anymore, you're using *= that operator means if the id INCLUDES InsertRecordUWStudentNPI, which, most probably, there's only one field that includes that term, unless there are multiple... 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.