Jump to content

If select list value "Yes", fill in one field with the other field that is a calculated value


Recommended Posts

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.

Link to comment
Share on other sites

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.

 

image.png.e82eb5195424c9a4e1fbba8954b98ded.png

 

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

image.png.896546a367bb6618821e920835f03bbb.png

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

×
×
  • Create New...