ptamzz ptamzz - 20 days ago 7
Javascript Question

how to fire event on file select

I've a form as

<form onSubmit="return disableForm(this);" action="upload.php" method="post" name="f" id="wizecho" enctype="multipart/form-data">
<input type="file" name="file" />
<button onClick="return disableForm(this),ajaxUpload(this.form,'wizecho_upload.php', '&lt;br&gt;Uploading image please wait.....&lt;br&gt;'); return false;">
Upload Image
</button>
</form>


It is to upload an image.

Here I need to click on the button to upload the image and I've to use
onClick
event. I want to remove the upload button and as soon as the file is selected at the input, I want to fire the event. How do I do that??

Answer

Use the change event on the file input.

$("#file").change(function(){
         //submit the form here
 });
Comments