Q:

How to fire event on file select in jQuery

0

How to fire event on file select in jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery change() method

You can simply use the jQuery change() method to fire an event to do something when the user select any file using the HTML file <input> type box.

Let's try out an example to understand how this method basically works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Fire Event on File Select</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function(){
        $("#myInput").change(function(){
            alert("A file has been selected.");
        });
    });
</script>
</head>
<body>
    <form>
        <input type="file" id="myInput">
    </form>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to get selected file name from input type file... >>
<< How to customize file input type box using CSS and...