Jump to content
  • 0

Reset Radio Buttons To False


RonAnderson

Question

I have a Checkbox (PAT Test Required) which when unchecked I want to programmatically reset the following elements:-

  1. Re-instate "Please Select" into the dropdown box (PAT Owner).
  2. Clear Date (PAT Inspection Date).
  3. Reset all three radio button to false (PAT Test Result).
  4. Clear any text from the textfield (PAT Unique Identifier).

Here's the code I've used to clear the date field, textfield and dropdown but I just can't get the radio buttons (PAT_Test_Result) to reset to false. The bold and underlined line is the one I'm looking to correct:-

<script>
document.querySelector("input[name*='PAT_Test']").addEventListener("change", function test(){

//checks the checkbox if no
if(document.querySelector("input[name*='PAT_Test']").checked == false){

//wipe the PAT values
 document.getElementById("InsertRecordPAT_Owner").value = "";
 document.getElementById("InsertRecordPAT_Inspection_Date").value = "";
 document.getElementById("InsertRecordPAT_Test_Result").value = false;
 document.getElementById("InsertRecordPAT_ID").value = "";

}

});

</script>

I know this is a big "Ask" but it's simply outside of my JS skills. Any help would be genuinely appreciated.

Checkbox_Unchecked.png

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

No response yet but I've been able to gather sufficient code snippets and configured a code which works. So, for anyone with the same issue, here's the code which works for my situation

<script>
document.querySelector("input[name*='Checkbox']").addEventListener("change", function test(){

//checks the checkbox if no
if(document.querySelector("input[name*='Checkbox']").checked == false){

//wipe the PAT values
var ele = document.getElementsByName("EditRecordPAT_Test_Result");
   for(var i=0;i<ele.length;i++){
      ele[i].checked = false;
   }
 document.getElementById("Textfield_ID").value = "";
 document.getElementById("InsertRecordDropdown_Owner").value = "";
 document.getElementById("InsertRecordTextfield_Date").value = "";

 }

});

</script>

The code needs to be placed in the FOOTER and turn off the HTML editor. Obviously you'll need to change "Checkbox" to the ID of your checkbox

Hope this can help save someone hours of searching :)

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