bootstrap dropdown checkbox
test checkbox on dropdown closing
by Greg
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<h1>jQuery Uploads</h1>
<a id="upload_btn" class="upload btn btn-default" >Upload CSV</a>
<div class="modal fade" id="uploadModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form method="post" enctype="multipart/form-data">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 id="dialogTitle" class="modal-title">SKU File Upload</h4>
</div>
<div class="modal-body">
Select CSV to upload:
<input type="file" name="fileToUpload" id="file_upload" multiple size="50" >
<p id="uploadTxt"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-default" value="Submit Content" name="submit">Submit</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<p id="uploadTxt"></p>
JavaScript
$('#upload_btn').click(function() {
$('#uploadModal').modal('show');
});
$(function(){
var files;
$('input[type=file]').on('change', prepareUpload);
$('form').on('submit', uploadFiles);
function prepareUpload(event) {
files = event.target.files;
var x = document.getElementById("file_upload");
var txt = "";
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; }
}
document.getElementById("uploadTxt").innerHTML = txt;
}
function uploadFiles(event) {
event.stopPropagation();
event.preventDefault();
var data = new FormData();
$.each(files, function(key, value)
{
data.append(key, value);
});
$.ajax({
url: 'php/upload.php',
type: 'POST',
data: data,
cache: false,
dataType: 'json',
processData: false,
contentType: false,
success: function(data, textStatus, jqXHR)
{
if(typeof data.error === 'undefined')
{
}
else
{
console.log('ERRORS: ' + data.error);
}
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log('ERRORS:...