Closed
Bug 286789
Opened 20 years ago
Closed 20 years ago
boolean javascript function returns value of embedded boolean functions rather than the true result
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: jabrwacki, Assigned: bugzilla)
Details
Attachments
(1 file)
|
1.45 KB,
text/html
|
Details |
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
Comment 1•20 years ago
|
||
(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
Closed: 20 years ago
Resolution: --- → INVALID
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 → ---
Comment 4•20 years ago
|
||
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
Closed: 20 years ago → 20 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•