[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

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;
<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"/>                

Open in new window

Im desperate for a quick solution if anyone has one.
  • 2
1 Solution
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

Roger BaklundCommented:
it never actually submits anything

Line 5 has "return false;", this prevents the form from being submitted.
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.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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