Click here to Skip to main content
15,886,919 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionHow I make a javascript wedget to place another website wedget Pin
Member 115008415-Mar-15 1:19
Member 115008415-Mar-15 1:19 
QuestionUnit testing for JavaScript/JQuery Code Pin
SaranshSrivastava28-Feb-15 20:53
SaranshSrivastava28-Feb-15 20:53 
Questionimage preview and save to a folder Pin
Member 1116631824-Feb-15 6:35
professionalMember 1116631824-Feb-15 6:35 
AnswerRe: image preview and save to a folder Pin
ZurdoDev24-Feb-15 11:01
professionalZurdoDev24-Feb-15 11:01 
AnswerRe: image preview and save to a folder Pin
Afzaal Ahmad Zeeshan28-Feb-15 22:06
professionalAfzaal Ahmad Zeeshan28-Feb-15 22:06 
GeneralRe: image preview and save to a folder Pin
Afzaal Ahmad Zeeshan16-Jun-15 5:43
professionalAfzaal Ahmad Zeeshan16-Jun-15 5:43 
GeneralRe: image preview and save to a folder Pin
Simewu16-Jun-15 12:08
professionalSimewu16-Jun-15 12:08 
AnswerRe: image preview and save to a folder Pin
Simewu16-Jun-15 12:09
professionalSimewu16-Jun-15 12:09 
Here:
<html>
<body>
<input id='input' type='file' onchange='newImage()'/>
<hr>
Preview:
<img id='img'/>
<hr>
<button onclick='downloadImage()'>Download</button>
<script>
var input=document.getElementById('input'); //the <input> element
var image=document.getElementById('img'); //the <img> element

function newImage(){
	if(!input.files||input.value=='') return; //if there is no file then exit function
	var file=input.files[0]; //get the file
	if(!file.type.match('image.*')){ //if file is not an image
		input.value=''; //clear input
		alert('Images only!');
		return; //exit function
	}
	var reader=new FileReader(); //now we read the image
	reader.readAsDataURL(file); //convert image into a string
	reader.onload=function(f){ //once the image string is received...
		image.src=f.target.result; //send the image string to the image element
	}
}

function downloadImage(){
	if(!image.src){
		alert('There is nothing to download!');
		return; //exit function if there is no image
	}
	var a=document.createElement('a');
	a.setAttribute('href',image.src);
	a.setAttribute('download','image.png');
	a.click();
}
</script>
</body>
</html>

Your welcome Shucks | :-\
Questionauto submit form Pin
joe-hanh24-Feb-15 6:22
joe-hanh24-Feb-15 6:22 
AnswerRe: auto submit form Pin
Afzaal Ahmad Zeeshan24-Feb-15 6:47
professionalAfzaal Ahmad Zeeshan24-Feb-15 6:47 
GeneralRe: auto submit form Pin
joe-hanh25-Feb-15 2:31
joe-hanh25-Feb-15 2:31 
QuestionGet selected Li from UL Pin
indian14323-Feb-15 15:02
indian14323-Feb-15 15:02 
AnswerRe: Get selected Li from UL Pin
Matt U.24-Mar-15 9:59
Matt U.24-Mar-15 9:59 
AnswerRe: Get selected Li from UL Pin
Simewu15-Jun-15 15:23
professionalSimewu15-Jun-15 15:23 
QuestionHiding a button which doesn't have an ID or Name Pin
indian14322-Feb-15 8:52
indian14322-Feb-15 8:52 
SuggestionRe: Hiding a button which doesn't have an ID or Name Pin
Kornfeld Eliyahu Peter23-Feb-15 6:07
professionalKornfeld Eliyahu Peter23-Feb-15 6:07 
GeneralRe: Hiding a button which doesn't have an ID or Name Pin
indian14323-Feb-15 12:05
indian14323-Feb-15 12:05 
AnswerRe: Hiding a button which doesn't have an ID or Name Pin
enhzflep27-Feb-15 5:48
enhzflep27-Feb-15 5:48 
QuestionNew to JQuery Pin
indian14319-Feb-15 9:08
indian14319-Feb-15 9:08 
AnswerRe: New to JQuery PinPopular
Richard MacCutchan19-Feb-15 21:30
mveRichard MacCutchan19-Feb-15 21:30 
GeneralRe: New to JQuery Pin
indian14320-Feb-15 11:35
indian14320-Feb-15 11:35 
GeneralRe: New to JQuery Pin
Richard MacCutchan20-Feb-15 21:47
mveRichard MacCutchan20-Feb-15 21:47 
GeneralRe: New to JQuery Pin
Amarnath S23-Feb-15 5:29
professionalAmarnath S23-Feb-15 5:29 
QuestionGetting text from UL using jquery Pin
indian14319-Feb-15 8:55
indian14319-Feb-15 8:55 
AnswerRe: Getting text from UL using jquery Pin
Dennis E White20-Feb-15 4:56
professionalDennis E White20-Feb-15 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.