Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function always returns true

Status
Not open for further replies.

jimmythegeek

Programmer
May 26, 2000
770
US
This may be elementary, or a stupid question, but why would the following function always return true even if cboOfferResult_? = acc?

numOfOffers and acc are variables set earlier in the code (numOfOffers = 2, and acc = 1)

====================================
function acceptedOffers () {
var retval = false;
for (i=1; i<=numOfOffers; i++) {
if (document.getElementById("cboOfferResult_" + i).value == acc) {
retval = true;
}
}
return(retval);
}
====================================

Thanks for any input in advance.

Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 

> why would the following function always return true even if cboOfferResult_? = acc?

Because you've told it to return true if cboOfferResult_? = acc with the line "retval = true;".

Dan
 
But it should only return true IF any offer results = acc. The function returns true even if there are NO offers that = acc.

Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Try putting in an alert like this so that you can find out what is setting the retval to true. Your function looks fine so it might be somewhere else in your code that is screwing things up.
Code:
function acceptedOffers () {
  var retval = false;
  for (i=1; i<=numOfOffers; i++) {
    if (document.getElementById("cboOfferResult_" + i).value == acc) {
      alert(i + ": " + document.getElementById("cboOfferResult_" + i).value + " == " + acc);
      retval = true; 
    }
  }
  return(retval);
}

-kaht

banghead.gif
 

> The function returns true even if there are NO offers that = acc.

Well that's the opposite of what you originally asked ;o)

Anyway, try changing your code to this, and see if it makes any difference:

Code:
function acceptedOffers () {
  for (i=1; i<=numOfOffers; i++) {
    if (document.getElementById("cboOfferResult_" + i).value == acc) return (true);
  }
  return (false);
}

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top