简体   繁体   中英

js submit without value

When I submit the form with JS. No value can be found.
This is my Code:

<!-- Form file --> 

<form id="postnotes" name="postnotes" action="./mechanic/comments.php" method="post">
    <textarea id="comments" class="comments" rows="4" name="comment" cols="50" placeholder="Make a note"></textarea>
</form>

<script type="text/javascript">
$(function() {
 $('textarea#comments').on('keyup', function(e) {
   if (e.which == 27 && ! e.shiftKey) {

        document.getElementById("postnotes").submit();
       }
   });
  });
 </script>
 <!-- file comments -->
 <?php if(isset($_POST['postnotes'])){
  echo 'hello its me your looking for';

 }
  else{echo 'nope srry';}

 ?>

Can somebody please help me.
Thanks in advance!

The submit is fine, although it seems odd to submit when the user presses Esc . It's the PHP checking for a submission that's incorrect. You're looking for a field using the name of the form ( postnames ). It's the name of the field that gets sent ( comment , the name of the textarea ), eg look in $_POST["comment"] , not $_POST["postnames"] .

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