Closed Bug 267005 Opened 20 years ago Closed 20 years ago

[FIXr]changing onsubmit dynamically doesn't work

Categories

(Core :: DOM: Events, defect, P1)

x86
All
defect

Tracking

()

RESOLVED FIXED
mozilla1.8alpha5

People

(Reporter: bugzilla, Assigned: bzbarsky)

References

()

Details

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.7) Gecko/20040803 Firefox/0.9.3
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.7) Gecko/20040803 Firefox/0.9.3

Changing the form.onsubmit-value (e.g. to prevent checking the inputs) by adding
a "this.form.onsubmit=null; return true" to a submit-button in the form doesn't
work in Mozilla & Firefox. See further down for workaround. 


Reproducible: Always
Steps to Reproduce:
1. load http://www.hernmarck.ch/a.html (or see aditional information)
2. press first button: alert with value og input appears - ok...
2. press second button "change onsubmit and send" - should be no alert


Actual Results:  
An alert box appears even if there is an onclick="this.form.onsubmit=null;
return true" on the second button. (onsubmit isn't changed to null)

Expected Results:  
send the form without showing the alert (without handling the original onsubmit
function).

Workaround:
read the value this.form.onsubmit, then change it. E.g.:
onclick="a=this.form.onsubmit; this.form.onsubmit = null; return true;"
(last btton in my example).

Works as expected in Konqueror/Opera/Internet Explorer.
Doesn't work on Mozilla, Firefox (Linux and Windows)

the code from my example:

<html>
 <head>
  <script type="text/javascript"><!--
   function test(t) {
    alert(t.i.value);
    return true;
   }
  //--></script>
 </head>
 <body>
  <form name="f" method="get" action="a.html" onsubmit="return test(this);">
   <input name="i"><br />
   <input type="submit" name="test1" value="send normal"><br />
   <input type="submit" name="test2" value="change onsubmit and send (bug)"
onclick="this.form.onsubmit = null; return true;"><br />

   <input type="submit" name="test3" value="change onsubmit, don't send"
onclick="this.form.onsubmit = null; return false;"><br />
   <input type="submit" name="test4" value="show onsubmit (then try test2)"
onclick="alert(this.form.onsubmit); return false;"><br />
   <input type="submit" name="test5" value="workaround for mozilla (change and
submit)" onclick="a=this.form.onsubmit; this.form.onsubmit = null; return
true;"><br />
  </form>
 <body>
</html>
Whe having to much traffic or bug is closed I'll remove the file from my
webspace.
Confirmed here on Windows XP therefore setting platform to all and status to new.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Linux → All
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8a5) Gecko/20041031
Firefox/0.9.1+

I have seen a similar report a few months ago, but I don't know whether
this is in fact a dup. The specification for the behaviour on changing
form.onsubmit is not simple, but IIRC it was felt that Mozilla was incorrect.
I was thinking of Bug 234833, which perhaps is definitely NOT the same thing.
(In reply to comment #4)
> I was thinking of Bug 234833, which perhaps is definitely NOT the same thing.

Well - it's slightliy different. Since the other bug has been fixed in april -
and I use Geck/20040803 it must be another one...
I hope this will be fixed also very quick - there seem to be a problem when
pressing the submit button and there are scripts changing the code to be
executed... (the "action" as in bug 234833 or the "onsubmit" as here..., maybe
there are other "functions" coming up in the future...)

I don't have an old version at hand - could someone check if the bug appeared
between Firefox 0.7 and FF 0.8? (as mentioned in bug 234833).
Thanx
I could test this on a Mozilla 1.5 (Gecko from Oct 2003) and everything is
working as expected... (no bug).
So the bug seems to have been added somewhere between Mozilla 1.5 and 1.7 - I
think it's hardly the same as in bug 234833 so who was the one who fixed that one?
This broke between 2003-11-17-10 and 2003-11-18-11 builds. In that range, bug
147811 looks most likely to be related.

Before that checkin, the nsEventReceiverSH::NewResolve code probably compiled
the event handler with the new null value or something....  After that checkin,
on assignment that code did nothing, and in nsEventReceiverSH::SetProperty we
just bail out because the value is not a function object.
Attached patch Proposed patchSplinter Review
Comment on attachment 164679 [details] [diff] [review]
Proposed patch

jst, thoughts?
Attachment #164679 - Flags: superreview?(jst)
Attachment #164679 - Flags: review?(jst)
And jst, do you think this is acceptable for branches?
Comment on attachment 164679 [details] [diff] [review]
Proposed patch

Looks good, and should be fine for the branches too (though it's too late to
get this into the aviary branch now).

r+sr=jst
Attachment #164679 - Flags: superreview?(jst)
Attachment #164679 - Flags: superreview+
Attachment #164679 - Flags: review?(jst)
Attachment #164679 - Flags: review+
Taking.
Assignee: events → bzbarsky
Priority: -- → P1
Summary: changing onsubmit dynamically doesn't work → [FIXr]changing onsubmit dynamically doesn't work
Target Milestone: --- → mozilla1.8alpha5
Fixed on trunk.  Not going to worry about the branches, I guess.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: