<div id="content">
OS <input id="os"><br/>
OS Name<input id="osname"><br/>
<input id="upload" type="file"/>
<button id="submitme" >Upload</button>
</div>
JavaScript
/*
// jQuery Ajax File Uploader
//
// @author: Jordan Feldstein <jfeldstein.com>
//
// - Ajaxifies an individual <input type="file">
// - Files are sandboxed. Doesn't matter how many, or where they are, on the page.
// - Allows for extra parameters to be included with the file
// - onStart callback can cancel the upload by returning false
*/
(function($) {
$.fn.ajaxfileupload = function(options) {
var settings = {
params: {},
action: '',
onStart: function() {
console.log('starting upload');
console.log(this);
},
onComplete: function(response) {
console.log('got response: ');
console.log(response);
console.log(this);
},
onCancel: function() {
console.log('cancelling: ');
console.log(this);
},
valid_extensions: ['gif', 'png', 'jpg', 'pdf'],
submit_button: null
};
var uploading_file = false;
if (options) {
$.extend(settings, options);
}
// 'this' is a jQuery collection of one or more (hopefully)
// file elements, but doesn't check for this yet
return this.each(function() {
var $element = $(this);
// Skip elements that are already setup. May replace this
// with uninit() later, to allow updating that settings
if ($element.data('ajaxUploader-setup') === true) return;
/*
$element.change(function() {
// since a new image was selected, reset the marker
uploading_file = false;
// only update the file from here if we haven't assigned a submit button
if (settings.submit_button == null) {
upload_file();
}
});
*/
if (settings.submit_button == null) {
// do...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.