Reputation: 37
I have a input type[file]
component.After the user browses and selects a file i need to download the selected file by clicking a button.
function download(){
...
}
<input type='file' id='file1'>
<button type='button' onclick='download()'></button>
Thanks, Nawaz Ahmed
Upvotes: 0
Views: 1385
Reputation: 2192
window.onload = function() {
var txt = document.getElementById('txt');
txt.value = window.onload + '';
document.getElementById('link').onclick = function(code) {
this.href = 'data:text/plain;charset=utf-8,'
+ encodeURIComponent(txt.value);
};
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="txtWrap">
<textarea id="txt"></textarea>
</div>
<a href="" id="link" download="code.txt">Download Above Code</a>
may be you can find some idea from here , i am not sure that i am right or wrong according to your question.
Upvotes: 1