Form Submit without Click Submit Button
<form id="formId" action="<?php echo Mage::getUrl('module/index/method') ?>" method="post"
enctype="multipart/form-data">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>">
<div id="upload-file-container">
<input id="img" type="file" name="img" onchange="this.form.submit()">
</div>
<input id="button" type="submit" value="Submit" name="submit" class="submit">
</form>
采用
document.getElementById("formId").submit();
Solution one:
You can call your form's submit
method in the onchange
event of your file input like this:
document.getElementById("file").onchange = function() {
document.getElementById("form").submit();
};
Here's a jsfiddle demo .
Solution Two:
You can also define the .submit
with an onchange
event inline:
<form action="http://your-url.com">
<input type="file" id="img" onChange="form.submit()" />
</form>
Here's a fiddle demo .
Solution Three:
The jQuery way of doing it:
$(function(){
$("#img").change(function(){
$("#form").submit();
});
});
document.getElementById("img").onchange = function() {
document.getElementById("formId").submit();
};
You can auto submit using this:
$(document).ready(function(){
setTimeout(function(){ $("#formId").submit(); }, 3000); });
Or specify exactly when you want to submit the form.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.