I want to create a button that when clicked, loads a form with text field and also option to add attachment (just for images). when submitted, these would be sent to myself. What is the best way to do this?
-
1Could you provide in your question the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example."Artem– Artem2018-09-30 08:56:08 +00:00Commented Sep 30, 2018 at 8:56
-
I suppose my skills are not there yet, hence the questionshatterstar– shatterstar2018-09-30 09:10:58 +00:00Commented Sep 30, 2018 at 9:10
Add a comment
|
1 Answer
To create a button that when clicked, loads a form with text field please see the code below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<title>Document</title>
</head>
<body>
<input type="file" id="fileBtn" onchange="uploadFile()">
</body>
<script>
function uploadFile() {
let file = document.getElementById('fileBtn').files[0];
let formData = new FormData();
formData.append("image", file);
$.ajax({
method: 'POST',
url: url,
cache: false,
processData: false,
contentType: false,
data: formData,
success: (res) => {
console.log(res)
}
})
}
</script>
</html>
3 Comments
Artem
Could you give some verbal comments to your comment as the bare code posted is difficult to comprehend for your post readers.
shatterstar
Thank you . Would you be able to provide more details in terms of what html code is needed here?
user9075203
@shatterstar here is the complete code, sorry i just saw you update