Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More than 1 form on a page 1

Status
Not open for further replies.

jl8789

MIS
May 22, 2003
293
US
Pressing the Enter key on the keyboard will submit a form on a page...but it does not work when there is more than 1 form, ie 2 or more submit buttons on a page. Which makes sense. The Enter Key then needs to be coded, and only know how to make it submit a particular form.

I can't find out just how to find focus on the form...checking each form's element's focus would probably work but be cumbersome...

I can't find a property or attribute of a form to see if any of it's elements has focus to figure out how to write the code. Do any exist? Or, how can I code this without having to check the focus of all existing elements on the page?

Thanks!
 
Hi,
Why not require the Submit button to be used instead of the Enter key?

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Users are used to pressing the enter key to activate a submit button on a page. It is easier than hovering over the submit button with the mouse for some. Is is a nicety, that's all. It would be nice to know which form I am on when capturing the enter key and then submitting each form accordingly.
 
best way, then, would probably be to use the onfocus event of each element to store the active form. you could dynamically add this event capturing using a loop, however, rather than adding the onfocus manually to each element.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hmmm, sounds interesting. Hate to do this to you, but could you provide some quick example on how to do this? How do I store the value of the forms? Perhaps the loop example would be the best way...
 
something like this:

Code:
var fActive;

function attachEvents(f) {
    var e = f.elements;
    for ( var i = 0; i < e.length; i++ ) {
        e[i].onfocus = function() { fActive = f; };
    }
}

window.onload = function() {
    attachEvents( document.forms['MyFirstFormName'] );
    attachEvents( document.forms['MySecondFormName'] );
}

you could then do your "enter" capturing, and if the enter button was clicked, submit the form as such:

Code:
fActive.submit();



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top