Submit a form using enter

110 views
Skip to first unread message

Dave L

unread,
Dec 10, 2008, 12:43:15 AM12/10/08
to Prototype & script.aculo.us
I am having trouble writing a function that will allow users to submit
a form that is in a modal popup using the enter key in IE6. It works
in all other browsers. I was thinking something along the lines of
this:

$('form_submit').onkeydown="if(event.keyCode==13){this.form.submit
();return false;};"

but this doesnt seem to work...Does anyone have any ideas?

pradeep saraswati

unread,
Dec 10, 2008, 4:03:28 AM12/10/08
to prototype-s...@googlegroups.com

hai

u are using $('form_submit')  --------does form_submit is the id of the form....

then it will surely does not gonna work in I.E

so you specify a name to the form....and access the form....


document.form.formname.onkeydown--------> this will work in ie...

i too faced this issue....just try this u r problem will be solved....

if u are too much particular in accessing form using $...then use $F and never access form using the id
IE will never know..what you are doing...if you access form by id

Regards
spradeepkumar

Dave L

unread,
Dec 10, 2008, 7:46:12 AM12/10/08
to Prototype & script.aculo.us
Im not sure I understand. login_form is the id of the form that I am
trying to submit. and form_submit is the id of the actual submit
button. I tried the following:

document.form.login_form.onkeydown="if(event.keyCode==13)
{this.form.submit();return false;};"

and also

$('login_form').form_submit.onkeydown="if(event.keyCode==13)
{this.form.submit();return false;};"

but no go. Thanks for your input.

Hector Virgen

unread,
Dec 10, 2008, 11:11:55 AM12/10/08
to prototype-s...@googlegroups.com
This is untested, but I would probably do something like this:

$$('form[name=login_form]').invoke('observe', 'keydown', function(event)
{
    if (event.keyCode === 13) {
        event.findElement('form').submit();
    }
});

-Hector

Miguel Beltran R.

unread,
Dec 10, 2008, 12:59:56 PM12/10/08
to prototype-s...@googlegroups.com
>Im not sure I understand.  login_form is the id of the form that I am
>trying to submit.  and form_submit is the id of the actual submit
>button. I tried the following:

I don't understand. what is your html code?
if your button is type submit, when it pressed send the form automatic



document.observe('dom:loaded', function(){
   $('login_submit').invoke('observe', 'submit', function(evt){
      evt.stop();
      //do stuff
   });
});
--
________________________________________
Lo bueno de vivir un dia mas
es saber que nos queda un dia menos de vida

Gabriel Gilini

unread,
Dec 10, 2008, 1:12:25 PM12/10/08
to prototype-s...@googlegroups.com
This is just stupid.
Why in the world would you want to stop the default action when the Enter key is pressed in a form, to do the exact same thing by yourself?

RobG

unread,
Dec 10, 2008, 10:08:56 PM12/10/08
to Prototype & script.aculo.us
You don't have to do anything. If an input has focus and the user
presses the enter key, the form's submit method will be called.


--
Rob

Rick Waldron

unread,
Dec 10, 2008, 12:15:57 PM12/10/08
to prototype-s...@googlegroups.com
I whipped this together, tested and confirmed:

document.observe("dom:loaded", function () {
$('login_form').observe('keydown', function (e) {

if ( e.keyCode == 13 ) {
//event.findElement('form').submit();
alert($F('login_str'));
}
});

}, false);


the form i set up looks like:

<form id=login_form>
<input type=text id=login_str>


</form>

Dave L

unread,
Dec 11, 2008, 6:28:16 AM12/11/08
to Prototype & script.aculo.us
Submitting a form in a modal popup in IE6 with enter does not work.

On Dec 10, 10:12 am, "Gabriel Gilini" <gabr...@usosim.com.br> wrote:
> This is just stupid.Why in the world would you want to stop the default
> action when the Enter key is pressed in a form, to do the exact same thing
> by yourself?
>
> Gabriel Gilini
>
> www.usosim.com.br
> gabr...@usosim.com.br
> gabr...@souagil.com.br

Dave L

unread,
Dec 11, 2008, 6:36:35 AM12/11/08
to Prototype & script.aculo.us
I tried all the above solutions but none seem to work. This is in a
modal popup, so its almost as if the javascript is not finding the
form element or something. Im using ruby on rails, so I defined the
id's of the form and the submit button inline if that helps at all:

<% form_remote_for :new_user, :url => {:controller =>
'account', :action => 'authenticate'},
:html => {:id => 'login_form'} do |f| -%>
<%= image_submit_tag "buttons/login.png", :id => 'form_submit'
%>
<% end %>

Hector Virgen

unread,
Dec 11, 2008, 10:06:14 AM12/11/08
to prototype-s...@googlegroups.com
Does the form (or modal) happen to be in an iframe?

-Hector

Gabriel Gilini

unread,
Dec 12, 2008, 2:04:11 AM12/12/08
to prototype-s...@googlegroups.com
There's no such thing as a "modal popup" in HTML specs, and you could do it a million ways. Your HTML is probably broken.
If you may post the generated markup plus the doctype and tested environments, it should be easier to spot the problem.

Dave L

unread,
Dec 12, 2008, 2:54:08 AM12/12/08
to Prototype & script.aculo.us
Yes, I am using the DOM popup Kit: http://www.methods.co.nz/popup/popup.html,
which I think uses iframes for the popup to function correctly in
IE6. Is that a problem?
Reply all
Reply to author
Forward
0 new messages