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', '<br>Uploading image please wait.....<br>'); 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??
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]').
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.
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').
Use the change event on the file input.
$("#file").change(function(){ //submit the form here });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With