Side navigation
#8186 closed bug (duplicate)
Opened February 06, 2011 07:54AM UTC
Closed February 06, 2011 01:36PM UTC
Last modified March 14, 2012 02:25PM UTC
Setting enctype attribute in IE8
| Reported by: | petrhk@volny.cz | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.5.1 |
| Component: | attributes | Version: | 1.5 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
Description
It can't set the enctype attribute in IE8:
f=$("<form>");
f.attr("enctype","multipart/form-data");//it doesn't work in IE8, form doesn't send a content of an upload file
f.attr("id","idx");//it works right
f.append('<input type="file" name="..." />');
...
It works in FF, but not in IE8. Only "enctype" attribute can't set with attr() method in IE8.
Code for IE8:
f=$("<form enctype="multipart/form-data"/>");
f.attr("id","idx");
...
Attachments (0)
Change History (3)
Changed February 06, 2011 12:51PM UTC by comment:1
Changed February 06, 2011 01:36PM UTC by comment:2
| component: | unfiled → attributes |
|---|---|
| milestone: | 1.next → 1.5.1 |
| priority: | undecided → low |
| resolution: | → duplicate |
| status: | new → closed |
Thanks for taking the time to contribute to the jQuery project by writing a bug report.
This is a known problem. You should be able to workaround this by doing
var f=$("<form>");
//note the camelcased attribute name works for most browsers including IE8
f.attr("encType", "multipart/form-data");
//needed for browsers where setting enctype isn't enough e.g. IE6/7
f.attr("encoding", "multipart/form-data");
Eventually this will be fixed in jQuery directly and the workaround no longer needed. You can check the ticket mentioned below for progress on this issue.
Example that bug:
<html> <head> <title>Example page for jQuery attr() bug - it can't set enctype attribute in form tag</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { //next two lines don't work in IE8, but they work in FF f=$('<form />'); f.attr("enctype","multipart/form-data"); //comment two previous lines, uncomment next line and it work in IE8 //f=$('<form enctype="multipart/form-data" />'); f.attr("method","post"); f.append('<input type="file" name="ffile" id="ffile" /><input name="fsubmit" id="fsubmit" type="submit">'); $(document.body).append(f); }); </script> </head> <body> <p> <?php if(@basename(htmlspecialchars($_FILES['ffile']['name'])))echo "Browser has sent a file ".$_FILES['ffile']['name']; else echo "Browser hasn't sent a file."; ?> </p> </body> </html>