I am working on a JSP page that allows user to upload an image file. This file will be later saved in database and will be used as their profile image. How can I open a file chooser dialog on click of a href link ?
I know about the <input type = "file" />
solution but that is not part of the page design and I must open the file chooser from a href only.
I am working on a JSP page that allows user to upload an image file. This file will be later saved in database and will be used as their profile image. How can I open a file chooser dialog on click of a href link ?
I know about the <input type = "file" />
solution but that is not part of the page design and I must open the file chooser from a href only.
- it can be done through javascript , no direct ways – Santhosh Commented Aug 7, 2014 at 5:34
3 Answers
Reset to default 2Try this ,
<input type="file" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" multiple />
<a href="" onclick="document.getElementById('upload').click(); return false">Upload File</a>
See the working FIDDLE
And also can be done using CSS effect ,
Read this link for information
try this for open file chooser on click of href button,
<html>
<head>
<script>
function openDialog()
{
document.getElementById("file1").click();
}
</script>
</head>
<body>
<input type="file" id="file1" style="display:none">
<a href="#" onclick="openDialog();return;">open Dialog</a>
</body></html>
HTML
<a href="#">
Your Anchor tag
</a>
<input type="file" id="file" />
Jquery
$("a").trigger("click");
$(document).on("click", "a", function(){
$('#file').click();
});
JSFIDDLE DEMO