• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

jquery, upload

I have generic web form in asp.net, just like contact information with name, address...and etc.

I would like to add upload button to allow user to upload document. How can I validate to make the attachment is there in jquery?

Thanks
0
Webboy2008
Asked:
Webboy2008
  • 2
  • 2
1 Solution
 
Julian HansenCommented:
Here is a working sample

<!doctype html>
<html>
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
  $('form').submit(function() {
    if ($('#files').val() == '') {
      alert('Please enter a file to upload');
      return false;
    }
  })
});
</script>
</head>
<body>
  <form>
    <input type="file" id="files" />
    <input type="submit" />
  </form>
</body>
</html>

Open in new window

0
 
Webboy2008Author Commented:
that is working but I am trying to merge with my existing codes...any ideas how to that?

<script type="text/javascript">
        $(document).ready(function() {
            $("#aspnetForm").validate({
                rules: {
                     <%=txtschool.UniqueID %>: {
                        required: true
                                               
                    },
                     <%=txtschoolclass.UniqueID %>: {                        
                        required: true
                    },
                      <%=txtmajor.UniqueID %>: {                        
                        required: true
                    },
                     <%=txtprofessor.UniqueID %>: {                        
                        required: true
                    },
                    <%=txttextbook.UniqueID %>: {                        
                        required: true
                    },
                    <%=txtschoolyear.UniqueID %>: {                        
                        required: true
                    },
                    <%=txtschoolyear.UniqueID %>: {                        
                        required: true
                    },
                    <%=txttotalpagenumber.UniqueID %>: {                        
                        required: true
                    },
                }, messages:
                {
                     
                   
                }
            });
        });
    </script>
0
 
Julian HansenCommented:
Ah, looks like you are using a validation plugin - without knowing which one can't test but would imaging it would be something like this.
Also don't know the id of your file upload control so you need to change that
<script type="text/javascript">
        $(document).ready(function() {
            $("#aspnetForm").validate({
                rules: {
                     <%=txtschool.UniqueID %>: {
                        required: true
                                               
                    },
                     <%=txtschoolclass.UniqueID %>: {                        
                        required: true
                    },
                      <%=txtmajor.UniqueID %>: {                        
                        required: true
                    },
                     <%=txtprofessor.UniqueID %>: {                        
                        required: true
                    },
                    <%=txttextbook.UniqueID %>: {                        
                        required: true
                    },
                    <%=txtschoolyear.UniqueID %>: {                        
                        required: true
                    },
                    <%=txtschoolyear.UniqueID %>: {                        
                        required: true
                    },
                    <%=txttotalpagenumber.UniqueID %>: {                        
                        required: true
                    },
                    <%=YOURFILEUPLOADBOXID %>: {                        
                        required: true
                    },
                }, messages:
                {
                     
                   
                }
            });
        });
    </script> 

Open in new window

0
 
Webboy2008Author Commented:
The code is working fine.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now