$(document).ready(function () {
$(".error_msge").hide();
var $deleteBtn = $("#btn_del"),
$sendBtn = $('#btn_send'),
$fileInput = $(".upload"),
$preview = $("#imageUploadForm"),
$errorLabel = $('#upload_error'),
$imagecontainer = $('#upload_image');
$deleteBtn.on("click", resetForm).hide();
$sendBtn.on("click", sendImage).hide();
$fileInput.on("change", showImage);
function resetForm() {
// Clear the preview
$preview.css("background-image", "none");
// Hide the buttons
$deleteBtn.hide();
$imagecontainer.show();
$sendBtn.hide();
// Empty the error message
$errorLabel.text('');
// Enable file selection
$fileInput.prop('disabled', false);
}
function showImage() {
var files = !! this.files ? this.files : [];
//var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg)$/;
// No file selected, or no FileReader support
//if (!files.length || !window.FileReader) return;
// If the file is a JPEG image
//if (regex.test(files[0].type)) {
// Create an instance of FileReader
var reader = new FileReader();
// Declare the onload callback before reading the file
reader.onload = function () {
// Set image data as background of div
$preview.css("background-image", "url(" + this.result + ")");
// Empty the error message
//$errorLabel.text('');
// Disable file selection
//$fileInput.prop('disabled', true);
// Show the buttons
$deleteBtn.show();
$sendBtn.show();
$imagecontainer.hide();
};
// Read the local file
...
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.