How do I change virtual form focus?

I've this issue where hitting 'enter' in a text input field submits different

virtual form.

Page has two virtual forms. On loading the page, the first virtual form's

submit button is focused by default. When user hits 'Enter' in an input

text field of the 2nd virtual form, the first virtual form gets submitted.

How can I make sure that the text field 'Enter' submits only the virtual form it belongs to?

Thanks for all the help.

-Vin

[495 byte] By [vin_stara] at [2007-11-26 15:09:12]
# 1

Has anyone else noticed that focus in text field of different virtual forms always brings submit button of first virtual in focus? This causes the first virtaul form to be submitted when one hits 'Enter' in text field of any other Virtual form. Or is it just me?

So how do I make sure that hitting 'Enter' in the text field only submits the virtual form to which the text field belongs? I've tried not very clean Javascript solution, but it works for Firefox and not for IE.

-Vin

vin_stara at 2007-7-8 8:59:45 > top of Java-index,Development Tools,Java Tools...
# 2

With regard to this functionality, the browser does not know about the virtual forms you have configured. Only the server knows that. When the page is submitted, all the literal form values are submitted, and the server figures out what to process based on the virtual forms you've configured.

When the user presses Enter, the first button in the literal form is assumed to have been pressed. That is a browser behavior, and that is why the first virtual form in your case is being processed.

Look in the HTML source for your page. There is a script tag for formElements.js. From that you can infer the URL where the browser is getting that script. Look at the source for formElements.js and look for a function called leaveSubmitterTrace or common_leaveSubmitterTrace. That function inserts a hidden field into your DOM that leaves a trace of which component id (not client id--client id is like "form1:someComponent" whereas component id is just "someComponent") submitted the page.

Upon form submission, your custom javascript can call that leaveSubmitterTrace function to leave a trace that a button in your 2nd virtual form is the one that submitted the page.

mbohma at 2007-7-8 8:59:45 > top of Java-index,Development Tools,Java Tools...
# 3
Thanks for the good explanation. I had figured out that it's client behavior but didn't get the clear picture of mechanics behind it. I think the easiest thing for me is to disable event keyCode=13, i.e. 'return'. This way user will be forced to use the right submit button.-Vin
vin_stara at 2007-7-8 8:59:45 > top of Java-index,Development Tools,Java Tools...