[thelist] JavaScript: Find matching number in list

Mike Carlson mike at mcarlson.net
Thu May 12 08:21:43 CDT 2005


The drop downs are for selecting shipping option. The first one is the
carrier (0 through 9) the second is the shipping option (0 through 9) the
third is the speed (0 through 9)

So '146' could be UPS 2DAY AM Delivery

The data is getting inserted into our SQL Server, then into our VAX EMS
system and it can only accept 3 character long strings for the shipping
options selected. There will never be more that 3 characters being passed. 

--Mike

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Christian Heilmann
Sent: Thursday, May 12, 2005 8:04 AM
To: thelist at lists.evolt.org
Subject: Re: [thelist] JavaScript: Find matching number in list

On 5/12/05, Chris Marsh <Chris.Marsh at callserve.com> wrote:
> [..]
> 
> > 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.

I tested my example, and values from selects seem to be strings by default,
therefore the above is a bit redundant.
You could also use the native toString() instead of using an own function
s1.options[s1.selectedIndex].value.toString()
 
> 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.

Exactly. I'd never rely on concatenating strings, but use an object or a
associative array instead.
-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester and archives
of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 




More information about the thelist mailing list