How to Check if file is attached to a list item in sharepoint 2010

A quick way to check if the user has attached a file to a list item that they just entered, is by using the PreSaveAction that runs on the “Save” button of the List item.
So whenever a user creates or edits and list item a javascript or jquery code can run in PreSaveAction() to check if the user has attached a document to the list item.

In code words here is how you do it -

//The below code uses jQuery Library for SharePoint Web Services and needs to be added into NewForm or Editform.aspx in a content editor webpart.

<script type=”text/javascript”>// <![CDATA[
var isAttached=0;

function PreSaveAction()
{
$(“input[name^='fileupload']“).each(function() {
if ($(this).val() != “”)
{
isAttached=1;
}
});

if(isAttached==1)
{
alert(‘File is attached.’);
}
else if(isAttached==0)
{
alert(‘No File is attached’);
}
}
// ]]></script>