1

I have a SharePoint site where I need to check for validation on a "Messaging" field.

If the user leave it blank then form will show an alert.

I also attached an image what it looks like.

So far I have this code:

<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script>
  if(!$("input[name='messaging']").is(':checked')  {
      alert("Please check message field");
   }
</script>

enter image description here

New contributor
and is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1

As you have not mentioned any conditions, I am assuming there are no conditions and you want your users to select either Yes or No for Messaging field.

OOTB Solution:

You can set the Default Value to your column so that it will always be selected either to Yes or No.

You can set the default value of column from column settings.

Code Solution:

function PreSaveAction(){
    if(!$("input[name^='Messaging']").is(':checked')) {
        alert("Please Check Message Field.");
        return;
    }
}

Add this code on EditForm.aspx page of list either in Script Editor or Content Editor webpart.

  • this is on the edit form. so I can't put any default settings to it. – and Feb 12 at 14:52
  • Try using the code in my updated answer and let me know if this works or not. – Ganesh Sanap Feb 12 at 15:19
0

Add the code below into script editor web part in edit form page to achieve it.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function PreSaveItem(){ 
    if(!$("input[name^='Messaging']").is(':checked')) {
        alert("Please Check Message Field.");
        return false;
    }
    return true;
}
</script>

SharePoint provide the "Yes/No" column, I suggest you use this column to instead of the Choice(Radio Buttons) column.

enter image description here

Your Answer

and is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.