0

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?

2
  • 1
    Could 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." Commented Sep 30, 2018 at 8:56
  • I suppose my skills are not there yet, hence the question Commented Sep 30, 2018 at 9:10

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Could you give some verbal comments to your comment as the bare code posted is difficult to comprehend for your post readers.
Thank you . Would you be able to provide more details in terms of what html code is needed here?
@shatterstar here is the complete code, sorry i just saw you update

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.