Closed Bug 134878 Opened 23 years ago Closed 21 years ago

script error (uncaught exception) should cancel form submission

Categories

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

defect

Tracking

()

RESOLVED INVALID
mozilla1.1beta

People

(Reporter: arkane, Assigned: alexsavulov)

References

Details

(Keywords: testcase)

Attachments

(1 file, 1 obsolete file)

From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:0.9.4)
Gecko/20011019 Netscape6/6.2
BuildID:    2002020406

The Following page javascript is acting as it should only at explorer!!
====================================================================
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META <--! within use of eval every parameter must have a -'0' after him!!)-->
<TITLE>Ishay's Musical Store</TITLE>
<SCRIPT language="javascript">
var contr;
function check_empty_text()
{
	contr = document.music;
	for (var loop = 1;loop < 7 && contr.elements[loop].value.length;loop++);
		return (loop);
}

function check_e_mail()
{
	contr = document.music.eMail.value;
	//im checking if the email is invalid and not the oppsite
	//thats why the "!" is for->and dont confuse to 
	//put && instead of ||!!!!!!!
	var booly;
	booly = contr.indexOf("@");
	return ( (booly <= 0) || (contr.indexOf(".",booly+2)<=0));
}
function check_gender()
{
	contr = document.music;
	return (!(contr.Gender[0].checked || contr.Gender[1].checked));
}
function check_phone()
{
	contr = document.music.PhoneNumber.value;
	var bopl = false;
	bopl = !(contr.indexOf("0")>=0
	||contr.indexOf("1")>=0
	||contr.indexOf("2")>=0
	||contr.indexOf("3")>=0
	||contr.indexOf("4")>=0
	||contr.indexOf("5")>=0
	||contr.indexOf("6")>=0
	||contr.indexOf("7")>=0
	||contr.indexOf("8")>=0
	||contr.indexOf("9")>=0);
	return bopl;
}

function validate()
{
	var tools = document.Select_Tools;
	document.music.hidyho.value = eval((tools.Violeen.value-'0')+	(tools.Guitar.value-'0')+(tools.Drums.value-'0'));
	var booly = true;
	//var how_much_empty = check_empty_text();
	if (check_empty_text() < 7)
	{
		window.alert("You havn't filled "+window.music.elements[check_empty_text()].name);
		window.music.elements[check_empty_text()].focus();
		window.music.elements[check_empty_text()].select();
		booly = false;
		
	}
	else if (check_e_mail()) 
	{
		window.alert("You didnt type the e-mail correctly");
		window.music.eMail.focus();
		window.music.eMail.select();
		booly = false;
	}
	else if (check_gender())
	{
		window.alert("Select your gender");
		window.music.Gender[0].focus();
		window.music.Gender[0].select();
		booly = false;
	}
	else if (check_phone())
	{
		window.alert("your phone does not contain digits!");
		window.music.PhoneNumber.focus();
		window.music.PhoneNumber.select();
		booly = false;
	}	
	
	return booly;
}
		
</SCRIPT>
</HEAD>
<BODY bgcolor=gold>
	<H1><FONT color=violet>Ishay's Musical Store</H1>
	<FORM name="Select_Tools">
	Select type of Violeen
		   <BR>
		<SELECT name="VioleenList"
onClick="Violeen.value=VioleenList.options[selectedIndex].value;">
			<OPTION value="25.50" selected >Violeen1 25.50
			<OPTION value="24.75">Violeen2 24.75
			<OPTION value="21.30">Violeen3 21.30</OPTION> 
		</SELECT>
		<INPUT  disabled maxlength =5 name="Violeen" value="0.00"><FONT color=violet>
		
		<BR>Select type of Guitar<BR></FONT>
		<SELECT name="GuitarList"
onClick="Guitar.value=GuitarList.options[selectedIndex].value">
			<OPTION value="25.50" selected>Guitar1 25.50
			<OPTION value="24.75">Guitar2 24.75
			<OPTION value="21.30">Guitar3 21.30</OPTION> 
		</SELECT>
		<INPUT  disabled readonly maxlength =5 name="Guitar" value="0.00"><FONT
color=violet>  
		
		<BR>Select Type Of Drums<BR></FONT>
		<SELECT name="DrumsList"
onClick="Drums.value=DrumsList.options[selectedIndex].value;">
			<OPTION value="25.50" selected>Drums1 25.50
			<OPTION value="24.75">Drums2 24.75
			<OPTION value="21.30">Drums3 21.30</OPTION> 
		</SELECT>
		<INPUT  disabled maxlength = 6 name="Drums" value="0.00">
		<BR>
		<INPUT  disabled maxlength = 6 name="Total" value="0.00">
		
		<BR>
		<INPUT type="button" value="Calculate Total Price" name="Calculate"
onClick="music.hidyho.value = Total.value =
eval((Violeen.value-'0')+(Guitar.value-'0')+(Drums.value-'0'))">
		</FORM>
		
		<FORM name="music" action="mailto:mob@bob.com" method="post" onSubmit="return
validate()">
		<BR><H2><CENTER>"Enter Your Details........."</CENTER></H2>
<P> 
<INPUT type="hidden" name="hidyho">
Last 
Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
		<INPUT name="LastName" type="text">
		<BR>First 
Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
		<INPUT name="FirstName" type="text">
		<BR>Address:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp; &nbsp;
		<INPUT name="Address" type="text">
	
<BR>City:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;
		<INPUT name="City" type="text">
		<BR>Phone Number:&nbsp;&nbsp;&nbsp;&nbsp;
		<INPUT name="PhoneNumber" type="text">
	
<BR>e-Mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;
		<INPUT name="eMail" type="text">
<BR>Country:&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
<SELECT 
style="WIDTH: 141px" name="Country"> 
<OPTION selected value="South Africa">South Africa</OPTION>
<OPTION value="Israel">Israel
<OPTION value="Gaza">Gaza</OPTION>
</SELECT>
<BR><BR><INPUT type=radio name="Gender">Male 
<INPUT type=radio name="Gender" >Female
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<INPUT type="submit"
value="Submit">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<INPUT style="WIDTH: 60px; HEIGHT: 24px" type=reset size=30 value=Reset>
	</FORM></FONT>
</BODY>
</HTML>


Reproducible: Always
Steps to Reproduce:
1.Copy the Code attached
2.run on netscape or mozilla(or any other gecko browser...)
3.

Actual Results:  The page will jump stright to the submit without entering the
javascript condtions(which have been proven to be true!!).

Expected Results:  Check the conditions of the javascript and stop the submit,
because the condtions for de - submitting the page have been full filled.
Attached file testcase (obsolete) —
The page has buggy js (it should be using document.music, not window.music,
imo).  So the onsubmit method throws an uncaught exception.  Shouldn't we be
stopping form submission in that case??
Assignee: sgehani → alexsavulov
Status: UNCONFIRMED → NEW
Component: XP Apps → Form Submission
Ever confirmed: true
OS: Windows XP → All
QA Contact: paw → vladimire
Hardware: PC → All
Even if i used fixed js, the page won t do what it meant to do!!!
Please attach a testcase with fixed JS.
I tested it, It working as I wanted with document.music, but the question is if 
it supposed to be that way - that i cant use window.music and should use 
document.music...although i can use both of them at explorer? please explain 
cause i feel i have to learn about it.
> the question is if it supposed to be that way - that i cant use window.music
> and should use document.music

That's correct.  Mozilla avoids polluting the global namespace (the "window."
namespace) whenever possible.  IE puts all sorts of crap in there.  As a result,
if I do:

<div id="music">
  <form name="music">
  </form>
</div>

and access window.music in IE, I don't know which I'll get (both element ids and
form names get attached to the window object and so window.music would give the
div if the form were not there, the form if the div were not there.  With both
there, there is no way to tell short of testing in IE and chances are that it's
not consistent between different IE versions).

In Mozilla, we support document.formname for forms to be backwards compatible
with IE and NS4.  Since NS4 does not support window.formname, your code breaks
there anyway; using document.music will make it work in all the browsers involved.

The _correct_ method of accessing the form (supported by Mozilla and IE5 or
later) is to give the <form> and id and then use document.getElementById.
We *shouldn't* be submitting if there's an uncaught exception, that is bad. 
Reduced testcase for that, anybody?  If the page gets fixed we'll leave this bug
open just for that.
Attached file Reduced testcase
So... I looked again.  The JS has a JS error and so stops execution, but the
error does _not_ trigger an exception as far as I can tell.  So if we check for
"exception" instead of "error" we would miss this.
Attachment #77249 - Attachment is obsolete: true
john:

how important is this actually? looks pretty important to me. (a look at the
simple testcase makes me think is very basic)

setting a milestone but we might want to fix this earlier
Priority: -- → P1
Target Milestone: --- → mozilla1.1beta
Keywords: testcase
Priority: P1 → P3
Priority: P3 → P2
Summary: This page wont do as the javascript, and will jump stright to submit!!! → We *shouldn't* be submitting if there's an uncaught exception
ah, i recall looking into the JS code (JS_interpret, i think) and such
exceptions are not propagated to the underlaying callers at all (for example the
HandleDOMEvent methods of the HTML...Element(s)). (see bug 138957 for details,
http://bugzilla.mozilla.org/show_bug.cgi?id=138957#c50).
Depends on: 233142
Given that we're dealing with form submission here and we're potentially sending
sensitive data over the network, I think I'd be ok with special casing this to
not perform the default action if an event handler threw an exception...
OK.  How do we tell?  ;)
Fixing this would break sites that have IE-only form validation scripts...
Summary: We *shouldn't* be submitting if there's an uncaught exception → script error (uncaught exception) should cancel form submission
Note that the patch in bug 233142 fixes this.
Fixed by bug 233142
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
This portion of the patch for bug 233142 was backed out in bug 235730, "Error
when trying to log in".
Reopening, then.  What's the plan?  Is this wontfix?
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
My proposal is that submission should only be cancelled if the event is
cancelled. Do exceptions cancel events?
In general, no.  That's what this bug was about.
I see no reason to special-case submit. ->INVALID
Status: REOPENED → RESOLVED
Closed: 21 years ago21 years ago
Resolution: --- → INVALID
Component: HTML: Form Submission → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: