Jump to content
  • 0

Checkbox select on condition


Cheeseybud

Question

Hi all,

I have a datapage with a field for worked hours and a checkbox (hidden) for Approved (true/false). This  will go to admin for approval.

Basically, I want the checkbox to auto select (true) on submission if the Worked hours field is <= 50 but false if the worked hours is >= 50.

I have tried numerous scripts, including some given from support, but I just cannot get it to work.

Any help would be greatly appretiated.

Thanks

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hello @Cheeseybud,

This code should work for the Submission form.
If the DataPage type differs, please update this thread and provide the DataPage type (it can be Details DataPage, Inline Add option on Tabular Report).

Add this code to the Footer of the Submission form, disable the HTML editor on the Advanced tab before passing the code, and change the field names in the code if needed.

<script>
document.addEventListener('DataPageReady', checkboxHandler);

function checkboxHandler(){

    const hoursField = document.querySelector('#InsertRecordWorked_hours'); //use your field name instead of Worked_hours
    const approvedField = document.querySelector('#InsertRecordApproved'); //use your field name instead of Approved

    hoursField.addEventListener('change', (event) =>{
        let hoursValue = parseFloat(event.target.value);
        if(hoursValue <= 50){
              approvedField.value = 'Y';
        }
        else{
             approvedField.value = '';
        }
        })
    document.removeEventListener('DataPageReady', checkboxHandler);
}
</script>

 

It is easier to check the Yes/No field by Trigger on record insert. But this works if Triggers are available in your plan.

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