boolean javascript function returns value of embedded boolean functions rather than the true result

RESOLVED INVALID

Status

()

Firefox
General
--
major
RESOLVED INVALID
13 years ago
13 years ago

People

(Reporter: jabrwacki, Assigned: Blake Ross)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

13 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1

If you have a boolean function that calls a boolean function within it, instead
of evaluating the result. Here is an example:

<input type="button" value="This button should alert false" onClick="doFunction2()">

<script language="javascript">
	function doFunction2()
	{
		alert(doFunction());
	}

	function doFunction()	
	{
		if(trueFunction() && falseFunction())
			return false;
		else
			return true;
	}
	
	function trueFunction()
	{
		return true;
	}
	
	function falseFunction()
	{
		return false;
	}
</script>

When you click the button, it alerts true, even though it should be false.
Instead of evaluating trueFunction() and falseFunction() and coming up with
false, it is only evaluating trueFunction and returning the result of that
function as if it were the final result.

Reproducible: Always

Steps to Reproduce:
1. Copy above html and javascript into an html page
2. Click the "This button should alert false" button
Actual Results:  
The browser alerted true

Expected Results:  
The browser should have alerted false
(trueFunction() && falseFunction()) == (true && false) == (false)

doFunction therefore returns true. 

DoFunction2() alerts the return value of doFunction().

DoFunction2() alerts "true".

There isn't any bug here...
Status: UNCONFIRMED → RESOLVED
Last Resolved: 13 years ago
Resolution: --- → INVALID
(Reporter)

Comment 2

13 years ago
Created attachment 178123 [details]
Bug Example
(Reporter)

Comment 3

13 years ago
I apologize for the bad code above. Please see the attached file I just 
uploaded. If you run this file in Internet Explorer, when you click the button, 
it will alert, "begin", "pass num: 1", "pass num: 2", "done", and then it will 
return false and not submit the form.

If you open this file in FireFox, it will alert, "begin", "pass num: 1", and 
then it will try to submit the form immediately. When you click the button, 
doFunction2() is called. doFunction2() calls some functions, then returns 
false. The form should not be submitted...and FireFox should not stop 
evaluating in the middle of the for loop on lines 29-33. At least, that is my 
understanding. 

Thank you.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
In this case, doFunction2 doesn't return at all, since it throws an exception.

You're using getElementById when none of your elements have IDs. The fact that
IE lets you do this is a bug in IE. See bug 174617.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 13 years ago13 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.