Javascript not called by pressing return key

My javascript function setHw is not called by pressing the return key in all of the following pages.
Please help.

<div id="rowPerPageDiv">
<form name="tagform" action="Hw.htm" method="post">
  <input type="hidden" name="currPage" value="0"/>
  Rows Per Page<input type="text" name="rowsPerPage" id="rowsPerPage" value="20" onsubmit="return setHw()"/>
  <input type="button" value="Apply" onClick="setHw()"><br>
</form>
</div>

<div id="rowPerPageDiv">
<form name="tagform">
  <input type="hidden" name="currPage" value="0"/>
  Rows Per Page<input type="text" name="rowsPerPage" id="rowsPerPage" value="20" onsubmit="return setHw()"/>
  <input type="button" value="Apply" onClick="setHw()"><br>
</form>
</div>

Get rid of the inline javascript event (eurgh!) and use a different method instead.

When you want it done on the enter key bring pressed, I presume that you want that so that you can run the script before the form is submitted.

Be direct and use the onsubmit event for the form instead.


// what to do when the form is submitted
function tagformSubmit() {
    setHw();
}

// assign tagformSubmit to each appropriate form
var forms = document.getElementsByTagName('form'),
    form,
    i;
for (i = 0; i < forms.length; i += 1) {
    form = forms[i];
    if (form.name = tagform) {
        form.onsubmit = tagformSubmit;
    }
}

The above script should be run from just before the </body> tag.

for example:


...
    <script type="text/javascript" src="/js/script.js">
</body>
</html>