Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

submit on enter multiple inputs

Tags:

forms

I have one input field that submits on pressing enter, like so:

<form action="" method="POST" >
  <input type="text" name="name"/>
  <input type="submit" style="display:none;" />
</form>

But when I add another field, pressing enter doesn't do anything:

<form action="" method="POST" >
  <input type="text" name="name"/>
  <input type="text" name="message"/>
  <input type="submit" style="display:none;" />
</form>

Why not? How can this be resolved?

Thanks a lot!


1 Answers

I wouldn't use display:none. I think you wanted visibility: hidden.

At any rate, I wouldn't use either. If you do not want a submit button I would first moved those / after the input names one space to the right and then use a hack suggested on SO.

<form action="index.php" method="POST" >
   <input type="text" name="name" />
   <input type="text" name="message" />
   <input type="submit" style="position: absolute; left: -9999px; 
   width: 1px; height: 1px;"/>
</form>

Also, please check out this Question as it has some great Answers on it. Submitting a form by pressing enter without a submit button

like image 80
donlaur Avatar answered Aug 02 '26 20:08

donlaur