Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

event listener behavior different in ie chrome

18 views
Skip to first unread message

Andrew

unread,
Sep 14, 2016, 9:15:22 AM9/14/16
to
Hi,

I found that the following

add_message_form.addEventListener('submit', function (e) {

e.preventDefault();

add_message_form.submit();

add_message_form.reset();

}, false)

triggers different behavior in chrome and ie. In chrome the reset is performed before the submit and in ie the submit is performed before the reset. To me it seems that the ie behavior is the correct one. Does anyone understand what is going on?

Thanks.

Andrew

Ben Bacarisse

unread,
Sep 14, 2016, 10:00:47 AM9/14/16
to
Andrew <andrew.m...@gmail.com> writes:

> I found that the following
>
> add_message_form.addEventListener('submit', function (e) {
>
> e.preventDefault();
>
> add_message_form.submit();
>
> add_message_form.reset();
>
> }, false)

Why all the newlines and spaces?

> triggers different behavior in chrome and ie. In chrome the reset is
> performed before the submit and in ie the submit is performed before
> the reset. To me it seems that the ie behavior is the correct
> one. Does anyone understand what is going on?

Calling submit does not guarantee that the form's content will be
collected then and there. What I suspect you are seeing is that the
form is submitted when the browser "has a moment" and this happens to be
after the reset has been done.

Whatever you are trying to do, you will have to find some other way to
do it. What is the overall objective?

--
Ben.

Andrew

unread,
Sep 14, 2016, 10:14:17 AM9/14/16
to
On Wednesday, September 14, 2016 at 4:00:47 PM UTC+2, Ben Bacarisse wrote:
Hi Ben,

I would like to submit the form then reset the form (so that the submitted form is not empty). How can I guarantee that the submit and the reset are performed in the order that I want them to be performed?

Thanks.

Andrew

Ben Bacarisse

unread,
Sep 14, 2016, 2:46:27 PM9/14/16
to
Andrew <andrew.m...@gmail.com> writes:

> On Wednesday, September 14, 2016 at 4:00:47 PM UTC+2, Ben Bacarisse wrote:
<snip>
>> ... What is the overall objective?
<snip>
> I would like to submit the form then reset the form (so that the
> submitted form is not empty). How can I guarantee that the submit and
> the reset are performed in the order that I want them to be performed?

This is not your overall goal. That's just what the code tries to do
written out in English -- i.e. there's no new information here.

I don't know any way to help you do what you want without more
information. The details depend on too many things left unspecified.

--
Ben.

Andrew

unread,
Sep 14, 2016, 2:53:25 PM9/14/16
to
On Wednesday, September 14, 2016 at 8:46:27 PM UTC+2, Ben Bacarisse wrote:
Hi Ben,

I have a form with a text box in it:

<form id="add_message_form" target="console_iframe1" method="post" action="add_message">
<input type="text" id="message" name="message" size="100" /> <br> <br>
</form>

I would like the following to happen when the user presses enter in the text box.

1) The form will be submitted.

2) The text in the text box will disappear.

Obviously, I want the form to be submitted with a nonempty text box value.

Andrew

Ben Bacarisse

unread,
Sep 14, 2016, 8:09:45 PM9/14/16
to
Andrew <andrew.m...@gmail.com> writes:

> On Wednesday, September 14, 2016 at 8:46:27 PM UTC+2, Ben Bacarisse wrote:
>> Andrew <*@gmail.com> writes:
>>
>> > On Wednesday, September 14, 2016 at 4:00:47 PM UTC+2, Ben Bacarisse wrote:
>> <snip>
>> >> ... What is the overall objective?
>> <snip>
>> > I would like to submit the form then reset the form (so that the
>> > submitted form is not empty). How can I guarantee that the submit and
>> > the reset are performed in the order that I want them to be performed?
>>
>> This is not your overall goal. That's just what the code tries to do
>> written out in English -- i.e. there's no new information here.
>>
>> I don't know any way to help you do what you want without more
>> information. The details depend on too many things left unspecified.
>
> Hi Ben,
>
> I have a form with a text box in it:
>
> <form id="add_message_form" target="console_iframe1" method="post" action="add_message">
> <input type="text" id="message" name="message" size="100" /> <br> <br>
> </form>
>
> I would like the following to happen when the user presses enter in the text box.
>
> 1) The form will be submitted.
>
> 2) The text in the text box will disappear.
>
> Obviously, I want the form to be submitted with a nonempty text box
> value.

I think you will have listen for the the iframe being loaded and reset
the form on that event.

--
Ben.

Cezary Tomczyk

unread,
Sep 15, 2016, 2:16:18 AM9/15/16
to
I'd rather wait until server respond and then, if success, then reset
the form. Otherwise show the error message and leave the form not cleared.

--
Cezary Tomczyk
http://www.ctomczyk.pl/
0 new messages