OZONE Asylum
Forums
DHTML/Javascript
complex switch case
This page's ID:
27696
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hello Sirius, If you got lots of conditions and ranges, why not write some sort of logic table coupled with case statement? say you want to do this on these conditions: range 1..6 : action1() range 10..44: action2() range 88..100: action3() etc...now define the range table as: var rangeTable = [1,6, 0, // 1..6 -> 0 10,44,1 // 10..44 -> 1 88,100,2 ]; Then write a small for loop that decides in what range does your value exist. Now suppose 'val' is your value you want to decide upon, here's the code: [code] var rangeTable = [1,6, 0, // 1..6 -> 0 10,44,1, // 10..44 -> 1 88,100,2 ]; var val = 88; var decision=-1; for (var i=0;i<rangeTable.length;i+=3) { if ((val >= rangeTable[i]) && (val <= rangeTable[i+1])) { decision = rangeTable[i+2]; break; } } switch (decision) { case 0: // for range 1..6 break; case 1: // 10..44 break; case 2: // 88..100 break; } [/code] HTH -- Regards, [url=http://lgwm.org/]Elias[/url]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »