Jump to content
  • 0

Uncheck a Chckbox if date entered in a date field - Details page


roattw

Question

9 answers to this question

Recommended Posts

  • 0

Hi @roattw

You can add the script below to your Header or Footer.
Please change EditRecordDate1 and EditRecordYesNo1 to your respective IDs.
image.png.5001283b9bc158b46b0d090e806647e5.pngimage.png.2451452d7c8072716812ce922b8b00c2.png

<script type="text/javascript">

document.addEventListener('DataPageReady', function (event) {

var txtDate = document.getElementById('EditRecordDate1')
 if (!txtDate.value) {
    document.querySelector('#EditRecordYesNo1').checked =true;
}
txtDate.addEventListener('change', function() {
  if (!txtDate.value) {
    document.querySelector('#EditRecordYesNo1').checked = true;
  } else {
    document.querySelector('#EditRecordYesNo1').checked = false;
  }
});

});

</script>

 

Link to comment
Share on other sites

  • 0

Hmm.  Just not sure how mine is different and not working.  Field names all correct.

Wonder if its because this DP is intially filtered by that field Im trying to check/uncheck, only showing "active" people so maybe it cant change that value when already being used in the filter.

 

DP2.png.9cad6fe2c53f7840f0b86dcd10ba2bcc.png- "Active"

 

Link to comment
Share on other sites

  • 0

Interesting twist.  I had a typo in the script.  Fixed that.  Didnt work.  I added a second checkbox field Active2, changed the script to that 

'#EditRecordActive2'

and it worked fine.  But it just wont work on that first Active checkbox.

 

I even removed "Active" as a search filter for the data and still not working.  There is something ablout that initial Active field it doesnt like.

Link to comment
Share on other sites

  • 0

Hello @roattw,

As I can see on your screenshot the field name is Termination_date.

The syntax to select the fields with the 'Text Field/Text Area/Dropdown/Checkbox/Listbox/Hidden' From element on the Details DataPage is EditRecordFIELDNAME

So, var txtDate should be: document.getElementById('EditRecordTermination_date').

KMCgqNQ.png

Hope this fixes the issue.

Link to comment
Share on other sites

  • 0

Hi @roattw

I tested the script on the sample DataPage and it works on my side.

It should work if both fields are editable (Active and Termination_date).

Please test the following script:

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

var terminDate = document.getElementById('EditRecordTermination_date');

function checkboxHandler() {

terminDate.addEventListener('change', function() {
  if (terminDate.value == '') {
    document.querySelector('#EditRecordActive').checked = true;
  } else {
    document.querySelector('#EditRecordActive').checked = false;
  }
})

document.removeEventListener('DataPageReady', checkboxHandler);
};

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