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

x
  • 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;
        });        
</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.
0
tonelm54
Asked:
tonelm54
  • 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

0
 
Roger BaklundCommented:
it never actually submits anything

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

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