2

When I open(edit) some item in a list I want to check with JavaScript if the user has attached any file in my Edit Form...

enter image description here

  • You'll need to provide some more context here... I understand you want to check if a user attached a file, but what are you attempting to do with the results? Are you looking to use javascript to check the edit form before an item is first submitted? Are you looking to check if items that were submitted have an attachment? – John-M Aug 1 '14 at 14:52
  • yes I want to check with JavaScript.... – Lugarini Aug 1 '14 at 14:56
4

You can add this script:

<script type="text/javascript" language="javascript">
function PreSaveAction() {
            var elm = document.getElementById("idAttachmentsTable");
            if (elm == null || elm.rows.length == 0)
{
                document.getElementById("idAttachmentsRow").style.display='none';
alert("Please attach Documents");
return false ;
}
else { return true ;}
}
</script>

Works very nice!

Does not work with SharePoint 2013, since it does not have "PreSaveAction"

  • I had used "PreSaveAction" in SharePoint Online and SharePoint 2013. It works – Abdul Hameed Oct 4 '17 at 11:46
  • do i need to replace idAttachmentsTable with the any id? @victor martins – jayant khushalani Apr 24 at 10:10
  • @jayantkhushalani, no need, leave it as idAttachmentsTable – Victor Martins Apr 25 at 11:39
  • working fine. thanks – jayant khushalani Apr 26 at 9:06
1

Didnt work for me , however after making few changes in the accepted code worked fine -

  function PreSaveAction() {

var attach= $("#getFile")[0].value; 
if (attach && attach == null || attach.length == 0)
{
document.getElementById("idAttachmentsRow").style.display='none';

alert("Please attach Documents in the Attachment Section.It is Mandatory");
return false ;
}
else { return true ;}
}

where #getFile is my custom attachment column Id

Your Answer

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.