I am trying to have my console print the contents of an input
field with a type
of file
. However, it's not doing this. It's actually behaving as though a form is being submitted, although there is no action attached to the form at this time. Can anyone explain why I'm unable to get the value of the desired field?
js
$("#submit").on("click", function(){
var image = $("#dept_image").val();
console.log(image);
})
html
<form enctype="multipart/form-data" method="post" id="departments" class="view">
<fieldset>
<label for="dept_name">Department Name:</label>
<input type="text" name="dept_name" id="dept_name" />
</fieldset>
<fieldset>
<label for="dept_image">Image:</label>
<input type="file" name="dept_image" id="dept_image" />
</fieldset>
<button name="submit" id="submit">Submit</button>
</form>