[英]Form Submitting on input change, but does not log onsubmit event. How to check if input submitted or not?
I have a form that submits on input change.我有一个提交输入更改的表单。 I have added an onsubmit event on form to log, if submit happens.
如果提交发生,我已经在表单上添加了一个 onsubmit 事件来记录。 But it does not log my submit.
但它没有记录我的提交。
Here is my code:这是我的代码:
<label for="id_cover_picture">Upload Cover</label>
<form action="" method="get" id="change_cover_picture_form">
<input type="file" name="cover_pic" id="id_cover_picture" style="display: none;">
</form>
Here is my JS code:这是我的 JS 代码:
<script>
const change_cover_picture_form = document.getElementById('change_cover_picture_form');
const form_cover_img = document.getElementById('id_cover_picture');
form_cover_img.addEventListener('input', () => {
console.log('input changed ...');
// even if it reloads , there will be data on localStorage
localStorage.setItem('input_change', 'input change ... cover image')
change_cover_picture_form.submit();
})
change_cover_picture_form.onsubmit = () => {
console.log('Form submitted ...');
// even if it reloads , there will be data on localStorage
localStorage.setItem('submit_cover', 'submitted ... cover image')
}
</script>
I am logging the input change and submitting the form, but not logging the submit...我正在记录输入更改并提交表单,但没有记录提交...
Please correct me, how to confirm submit, and why the onsubmit is not working.请纠正我,如何确认提交,以及为什么 onsubmit 不起作用。 I have even tried with,
addEventListener('submit')
我什至尝试过
addEventListener('submit')
Expected Answer:预期答案:
Log the submit, and perform some action if submit happens记录提交,并在提交发生时执行一些操作
There's no way to submit the form.没有办法提交表格。 Add a submit input to the form and then click that.
向表单添加提交输入,然后单击它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.