1

I was looking at one image web site and was puzzled by the javascript they used. The web site has a image, below that there is a text input field you can input your comments. After you input your comments, you press the enter key to commit the comment.

The html looks like this:

 <form class="-cx-PRIVATE-PostInfo__commentCreator" data-reactid=".0.1.0.0.0.2.2.1">
   <input class="-cx-PRIVATE-PostInfo__commentCreatorInput" placeholder="Add a comment…" type="text" value="" data-reactid=".0.1.0.0.0.2.2.1.0">
 </form>

There is no action in the form and no submit button. How can they submit the form?

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
fireman
  • 193
  • 8
  • Probably JavaScript to attach handlers or fire AJAX requests separately without doing a whole page / form submission. The HTML you see in "View source" (prior to F12 DOM viewers) is the HTML received by the client and is **not** a representation of the current state of the DOM. – Dai Sep 19 '15 at 00:35
  • possible duplicate of [Javascript submit textbox on ENTER](http://stackoverflow.com/questions/8894226/javascript-submit-textbox-on-enter) – Shiji.J Sep 19 '15 at 00:36
  • Use F12 in your browser to inspect the `
    ` element and any controls contained inside, look for functions bound to events like `submit` or `click`.
    – Dai Sep 19 '15 at 00:36

2 Answers2

3

The form's action attribute will default to the current URL.

Try filling in some text and hitting enter:

<form>
    <input type="text" name="lookInTheUrlAfterHittingEnter" />
</form>

As @Traktor53 says, hitting enter whilst focus is on the text input will submit the form.

Adrian Lynch
  • 8,237
  • 2
  • 32
  • 40
0

Input elements of type text (for a single line of text) have submitted their form if the enter key is pressed while filling them in since the year dot AFAIK. I did not find any mention of this in HTML5's documentation for this input type element.

traktor
  • 17,588
  • 4
  • 32
  • 53