Jump to content
  • 0

Select a checkbox based on dropdown value - caluclated value vs script


roattw

Question

Have tried most of the suggested methods (both calculated value and javascript) but none worked, still having issues so it must be something unique to my setup.

New record entry/ Insert Record.

Have text field set as dropdown  = [@field:Role]  (Resident, Faculty, Fellow)

Have a checkbox set as Yes/No = [@field:Alumni]

If Role dropdown = "Resident" I need Alumni to be checked.  If not Resident, left unchecked.

I was getting invalid SQL orf ther Incompatible data type, text but needs to be Yes/No.

The bottom formula worked using the CAST function, however if not Resident it remains as No where I really need a check box because dropdown could = Faculty and need to be ALumni.

Possibly wrong original approach using Yes/No field?

Thanks all.

caspio-checkbox.thumb.png.1e6b6084db5ae1b7958150afff93dc97.png

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi @roattw,

Are you using a Submission Form? If so, can you try the following:

1. Edit your DataPage and go to Configure Fields

2. Add a HEader and Footer. Select Footer and disable the HTML editor and paste the following:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
    const selectElement = document.querySelector('#InsertRecordRole');

selectElement.addEventListener('change', (event) => {
if(selectElement.value == "Resident"){
document.querySelector("#InsertRecordAlumni").checked = true;
}else{
document.querySelector("#InsertRecordAlumni").checked = false;
}
});

});
</script>

 

If you're using an Update Form or a Details Page, simply replace all instances of "InsertRecord" with "UpdateRecord"

Link to comment
Share on other sites

  • 0
On 10/11/2022 at 5:20 PM, futurist said:

Hi @roattw,

Are you using a Submission Form? If so, can you try the following:

1. Edit your DataPage and go to Configure Fields

2. Add a HEader and Footer. Select Footer and disable the HTML editor and paste the following:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
    const selectElement = document.querySelector('#InsertRecordRole');

selectElement.addEventListener('change', (event) => {
if(selectElement.value == "Resident"){
document.querySelector("#InsertRecordAlumni").checked = true;
}else{
document.querySelector("#InsertRecordAlumni").checked = false;
}
});

});
</script>

 

If you're using an Update Form or a Details Page, simply replace all instances of "InsertRecord" with "UpdateRecord"

This did seem to work and was on a submission page. Thank you.

It did however affect one of my rules, possibly due to how the script is listensing and interpreting a change.  The rule seems to run fine  if I manually check Alumni box, but not if its checked by then script running.  This Rule hides the field "Graduation Year" if Alumni not checked.  So when alumni checked,  Graduation Year field shown.   This Rule works without the script in place. 

No script: Alumni checked = Grad Year shown:

role2.thumb.png.71284cc9af489ed7595dc2b506ff9f5b.png

With script: Alumni checked = grad year not shown (Rule not run):

role1.png.e396e3fda6eed6f1614959412a4f69cf.png

Interestingly, if I manually uncheck the script-applied checknox then recheck it manually the Grad YEar appears (Rulke run).  So rule runs with manual box check, but not with scripted box check.

 

 

 

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
Answer this question...

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