Form submit with file

Im trying to get the following code to work so I can upload a file to a form handler, however for some readon it never actually submits anything to my form.

My simple test code is:-
<script type="text/javascript">
$(document).ready(function() {    
    $('#frmUpload').submit(function() {
        alert('Starting Upload.');
        return false;
        });        
</script>
<form id="frmUpload" action="upload.php">
    <div style="width:100%;">
        <textarea id="txtDescription" cols="30" rows="14"></textarea><br/>
        <input type="file" name="filUpload" /><br/>
        <input type="submit" value="Upload"/>                
    </div>
</form>

Open in new window


Im desperate for a quick solution if anyone has one.
tonelm54Asked:
Who is Participating?
 
JonNormanConnect With a Mentor Commented:
You also have mismatched brackets - you need another }); around line 6, so I suspect that you didn't get the alert at all, and the return false didn't kick in.
0
 
Roger BaklundCommented:
When using <input type="file" ... /> you also need to set the enctype property on the form:

<form id="frmUpload" action="upload.php" enctype="multipart/form-data">

Open in new window

0
 
Roger BaklundCommented:
it never actually submits anything

Line 5 has "return false;", this prevents the form from being submitted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.