Skip to content

Instantly share code, notes, and snippets.

@AlexGalhardo
Created September 4, 2018 13:12
Show Gist options
  • Save AlexGalhardo/18db107e217ff29a1231ca3336fed0d4 to your computer and use it in GitHub Desktop.
Save AlexGalhardo/18db107e217ff29a1231ca3336fed0d4 to your computer and use it in GitHub Desktop.
<title>Preview Imagem</title>

Cadastrar Imagem





		<input type="submit" value="Cadastrar">
	</form>		
	
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	
	<script>
		function previewImagem(){
			var imagem = document.querySelector('input[name=imagem]').files[0];
			var preview = document.querySelector('img');
			
			var reader = new FileReader();
			
			reader.onloadend = function () {
				preview.src = reader.result;
			}
			
			if(imagem){
				reader.readAsDataURL(imagem);
			}else{
				preview.src = "";
			}
		}
	</script>
   
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment