Closed Bug 156845 Opened 23 years ago Closed 23 years ago

Javascript code does not submit correct button that was clicked

Categories

(Core :: DOM: Core & HTML, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: ambodnar, Assigned: john)

Details

Attachments

(1 obsolete file)

From Bugzilla Helper: User-Agent: Mozilla/5.0 Galeon/1.2.5 (X11; Linux i686; U;) Gecko/0 BuildID: 20020630 There are 3 submit buttons, all named the same, but with different values. Add, Edit, and Delete. When the Delete button is clicked it invokes a OnClick that calls javascript function to return a value. The javascript function sets a variable to a true or false value the window.confirm returns. Then an if statement to see if the user clicked Yes. If so, a document.formname.submit() is issued. In Mozilla, the form is just submitted, but the Delete button's value isn't sent along. In other browsers, the value of the Delete button is sent. Reproducible: Always Steps to Reproduce: See Additional Information for code to reproduce. If the code doesn't display correct, contact me and I will setup a link that displays this problem. <script> function validate_delete() { var confdelete = window.confirm('Are you sure you want to delete this user?') if (confdelete == true) { document.users.submit() } else { return false } } </script> <form name=users method=POST> <input type=submit name=action value=Add> <input type=submit name=action value=Edit> <input type=submit name=action value=Delete onClick="return validate_delete()">
it seems very wrong to put several buttons with the same name.
Browser, not engine ---> DOM Level 0 Confirming report using Mozilla trunk binary 20020701xx on WinNT. Note: I can see the bug even if I delete the two other buttons: <script> function validate_delete() { var confdelete = window.confirm('Are you sure you want to delete this user?') if (confdelete == true) { document.users.submit(); return true; } else { return false; } } </script> <form name=users method=submit> <input type=submit name=action value=Delete onClick="return validate_delete()"> </form> I will attach this below. Note I changed the |method| attribute from "post" to "submit", so that we can see the query items appear in the URL bar once the submit button is hit -
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
Attached file HTML testcase (obsolete) —
Comment on attachment 91014 [details] HTML testcase Oops! Have to obsolete the attachment; the Bugzilla server doesn't like us to submit to it!
Attachment #91014 - Attachment is obsolete: true
Just save the source in Comment #2 locally and click the Delete button. Note I have changed the form method to "submit" instead of "post". I have also added a |return true;| to the positive branch of the validate_delete() function - Here's what I get. My URL on load is file:///C|/WINNT/Profiles/pschwartau/Desktop/156845.html After clicking the Delete button (and confirming "OK"), I have: NN4.7 file:///C|/WINNT/Profiles/pschwartau/Desktop/156845.html?action=Delete Mozilla file:///C:/WINNT/Profiles/pschwartau/Desktop/156845.html? IE6 file:///C:/WINNT/Profiles/pschwartau/Desktop/156845.html?action=Delete So in Mozilla, the value of the <input> is not being sent -
Status: UNCONFIRMED → NEW
Ever confirmed: true
What is happening here is that the case when you call document.users.submit() does not return false, so the <input type="submit"> also submits. You get two submissions -- one from the submit() call, one from the <input>. In Mozilla, we do not allow multiple submits from the same form at the same time (since that can lead to bad double-submit problems on the server side; in your case you would get two deletions if your server-side code did not check the value of the button used to submit (eg if there was only one submission button)). So the first submit (from calling submit()) happens, and that does not know what button to send. The second submit (from the <input type="submit"> does not happen). It looks like your code should just return "true" in the "confdelete == true" case and let the <input type="submit"> handle the submission...
Assignee: jst → jkeiser
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: