[thelist] JavaScript: Find matching number in list

Chris Marsh Chris.Marsh at Callserve.com
Thu May 12 07:54:23 CDT 2005


[..]

> con=s1.options[s1.selectedIndex].value+s2.options[s2.selectedI
> ndex].value+s3.options[s3.selectedIndex].value;

I would ensure that the values were explicitly typed as strings to avoid the
+ operator performing an addition fnuction rather than a concatenation
function.

function MakeString(i)
{
  i += '';
  return i;
}

var con = MakeString(s1.options[s1.selectedIndex].value);
con += MakeString(s2.options[s2.selectedIndex].value);
con += MakeString(s3.options[s3.selectedIndex].value);

Something along those lines should work, although the code above is
untested.

Something else to consider is that the system you describe would appear to
limit effective functionality to select boxes of which only one may have
more than ten elements. Consider the concatenated result '1111'. Is this
'11'+'1'+'1', '1'+'11'+'1' or '1'+'1'+'11'? In my limited experience it has
proven less time consuming to produce solutions that accommodate expansion
even on such a small scale as this. Is it possible to use a separator? For
example, '1|11|1' uniquely expresses the combination of the three values,
and if one is performing string functions anyway there should not be much
more overhead in including pipes.

Even if it a rock solid certainty that your current system will never have
more than ten items in more than one select box, if it works well (as one
would hope) then circumstances in which a client/boss/colleague request that
a similar system be implemented elsewhere are not beyond the realms of
possibility. If you have already coded around the limits idfentified here,
then the port is trivial, if not then you may be faced with recoding the
entire system.

[..]

All the above IMHO, YMMV, HAND.

Regards

Chris Marsh

_______________________________________________________________________
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender and delete the email immediately. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 

Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company.

Finally, the recipient should check this email and any attachments for the presence of viruses. Callserve Communications accepts no liability for any damage caused by any virus transmitted by this email. _______________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service.


More information about the thelist mailing list