简体   繁体   中英

Is it possible to submit a form with onpaste?

I'm trying to make a form that once you paste something it self submit. I have the following code:

<form>
    <textarea onpaste=submit></textarea>
</form>

javascript code I've tried:

<form action="./1.php" method="post" id="frm1" name="frm1"> 
<textarea placeholder="Paste Here" onpaste="document.frm1.submit()"></textarea>

Previous code was not working for some reason.

What javascript code should I use to make it work?

You can try this code. It will automatically submit the form once anything is pasted inside:

<html>
<body>
  <form id="myform"><textarea></textarea></form>
</body>
<script>
  document.getElementById("myform").addEventListener("paste", function() {
   this.submit();
  });
</script>
</html

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM