Note that there are some explanatory texts on larger screens.

plurals
  1. POHitting enter does not invoke javascript function in HTML form
    primarykey
    data
    text
    <p>I have a simple form with one input field. It works fine when I use the submit but hitting enter in the text field reloads the page with the form variable in the URL.</p> <p>I looked through the many solutions available online (except for JQuery since it seems like overkill for something this simple) and haven't been able to get 'enter' to work. Any help would be great</p> <pre><code>&lt;form name="myform" action="" method="GET" &gt; Enter text: &lt;br&gt; &lt;input type="text" name="queryinput" onkeyup="if(isEnterPressed(event)){initialize(this.form.queryinput.value);}"&gt;&lt;P&gt; &lt;input type="button" name="Search" value="Search" onClick="initialize(this.form.queryinput.value);"&gt; &lt;input type="submit" value="Reset" onclick="reset();" /&gt; &lt;/form&gt; function isEnterPressed(e){ var keycode=null; if (e!=null){ if (window.event!=undefined) if (window.event.keyCode) keycode = window.event.keyCode; else if (window.event.charCode) keycode = window.event.charCode; }else{ keycode = e.keyCode; } } return (keycode == 13);} </code></pre> <p>Edit 1: Version using onsubmit instead of the keycode listeners:</p> <pre><code>&lt;form name="myform" action="" onsubmit="return initialize(this.form.queryinput.value)" method="GET"&gt; Enter text:&lt;br&gt; &lt;input type="text" name="queryinput"&gt; &lt;input type="submit" value="submit" &gt; &lt;input type="button" value="Reset" onclick="clearAllPoints();"/&gt; &lt;/form&gt; </code></pre> <p>Using onSubmit causes the click button to behave the same as hitting enter but neither version works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload