Last active
March 6, 2017 06:10
-
-
Save mikhy888/d56db0c0e85bd927a3552b34ce0cdb9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--here is the html--> | |
<input id="txt" type = "text" value = "Choose File" onclick ="javascript:document.getElementById('file').click();"> | |
<input id = "file" class="upload-opt" type="file" style='display: none;' name="upload"/> | |
<!--here is the script--> | |
$('#file').on( 'change', function() { | |
var myfile= $( this ).val(); | |
var ext = myfile.split('.').pop(); | |
//alert(ext); | |
if(ext=="pdf" || ext=="docx" || ext=="doc" || ext=="txt" || ext=="odc" || ext=="jpg" ){ | |
if(this.files[0].size > 1048576){ | |
$('.upload-opt').next('.validation-text').text('File is too big!'); | |
this.value = ""; | |
} else { | |
var value = $(this).val(); | |
$("#txt").val(value); | |
} | |
} else { | |
$('.upload-opt').next('.validation-text').text('This kind of file cant be uploaded'); | |
this.value = ""; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment