# html return key causes unwished for execution of a submit button.



## andynic (May 25, 2007)

Hi,

I have a fairly complex HTML form which contains 3 divisions. Each division contains several tags.
No matter where the focus is, pressing the return key, causes an unwished for execution of one of these submit buttons -- always the same button which is in the 3rd division.

The syntax of the submit button that executes is this:

Would anyone have any idea as to what might be causing the return key to be, so to speak, coupled to this button?

I've put some additional information below that may or may not be relevant to the question.

Any ideas would be greatly appreciated.

Thanks for your help.
Andynic

Some additional information:
=====================
When the form loads, the body tag puts the focus on the first field.

that is, the focus is on this button:

If the user enters a value and presses the return key instead of the tab key, the form executes the button shown above (the one that has name="MITM_NEWrefreshSlctdImgs").

The validateNull function looks like this.
function validateNull(val, fldNm, fldId)
{
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;

if ( val == "" )
{
alert (fldNm + " field requires a value. It cannot be null.");
document.getElementById(fldId).focus();
}
}


----------



## ehymel (Aug 12, 2007)

Without seeing the full code of the page, my only suggestion would be to surround each division with its own tag. I'm not sure about this, but my suspicion is that hitting the "return" key will try to submit using the last submit button within that form.

If breaking a single form into multiple forms prevents data from different divisions from being submitted, a work-around would be defining hidden fields within each smaller form representing data from the other non-included forms, then using javascript to fill in those hidden values among the other forms. Sounds complicated. Actually it's a pain in the butt way to do it, but it's what I've got for a suggestion for now


----------



## andynic (May 25, 2007)

Hi Ehymel.
Thanks for your response. I will give this a try in the coming days. Will let you know how it turns out.
Andynic


----------

