Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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??

like image 720
ptamzz Avatar asked May 09 '11 21:05

ptamzz


People also ask

How to trigger file upload jQuery?

If you want to just have the file name show up, you can cut out the slashes. $('input[type=text]'). click(function() { $('input[type=file]'). trigger('click'); }); $('input[type=file]').

How can you tell if a file is canceled and clicked on input?

The easiest way is to check if there are any files in temporary memory. If you want to get the change event every time user clicks the file input you can trigger it. Show activity on this post. In my case i had to hide submit button while users were selecting images.

How would you programmatically fire all the listeners to the click event on all the p elements?

Approach: Whenever you want to perform a click event programmatically, at your specific condition, just use JavaScript in-built click() function by DOM object. For example: document. getElementById('your_input_type_file_element_id').


1 Answers

Use the change event on the file input.

$("#file").change(function(){          //submit the form here  }); 
like image 197
Vincent Ramdhanie Avatar answered Sep 28 '22 11:09

Vincent Ramdhanie