IF statements being skipped in javascript
Posted: Sat Oct 23, 2004 2:04 pm
Here is my problem: I am using php to get a querystring from the url sent to my page, so it's something like index.php?menu=16. The menu integer is storing a bitwise value so that I can break down what menus should be expanded when they go to that page.
As you can see from my constants, a value of 1 means main menu is expanded, 2 means chop menu is expanded. A value of 3 would mean main AND chop menus are expanded.
The IF statements in the initMenuFlags function are my problem. No matter what combination of menus should be expanded, only the FIRST IF statement is being executed. For example, menu passes a value of 12. That means tutorial and beat menus are expanded. Only the IF statement for tutVal is being executed and therefore only that menu is being expanded. The script is completely ignoring the IF statement for beatVal.
What can I do to remedy this so that all IF statements are being evaluated? For those who aren't aware of what I am doing, imagine the menu value being in binary and being 5 bits. Originally it is 00000. Each bit acts as a toggle for a menu. Main menu on would be 00001. Tutorial menu on would be 00100. My if statements are checking if my menuflags variable contains the toggle for each menu.
Thanks for any help, its much appreciated!
As you can see from my constants, a value of 1 means main menu is expanded, 2 means chop menu is expanded. A value of 3 would mean main AND chop menus are expanded.
The IF statements in the initMenuFlags function are my problem. No matter what combination of menus should be expanded, only the FIRST IF statement is being executed. For example, menu passes a value of 12. That means tutorial and beat menus are expanded. Only the IF statement for tutVal is being executed and therefore only that menu is being expanded. The script is completely ignoring the IF statement for beatVal.
What can I do to remedy this so that all IF statements are being evaluated? For those who aren't aware of what I am doing, imagine the menu value being in binary and being 5 bits. Originally it is 00000. Each bit acts as a toggle for a menu. Main menu on would be 00001. Tutorial menu on would be 00100. My if statements are checking if my menuflags variable contains the toggle for each menu.
Thanks for any help, its much appreciated!
Code: Select all
<?php if (isset($_GETї'menu'])) $menuFlags=$_GETї'menu']; else $menuFlags=0; ?>
<script language="javascript1.3">
const mainVal=1;
const chopVal=2;
const tutVal=4;
const beatVal=8;
const linkVal=16;
function redirectURL(myURL) {
//alert("menuflags " + menuFlags);
myURL = myURL + "&menu=" + menuFlags;
window.location=myURL;
}
function initMenuFlags() {
menuFlags=<?php echo $menuFlags ?>;
if(menuFlags & mainVal)
neonixToggle('subMain','mnuMain','',false,'Main', 0);
if(menuFlags & chopVal)
neonixToggle('subChopShop','mnuChopShop','',false,'Chop Shop', 0);
if(menuFlags & tutVal)
neonixToggle('subTutorial','mnuTutorials','',false,'Tutorials', 0);
if(menuFlags & beatVal)
neonixToggle('subBeats','mnuBeats','',false,'Beats', 0);
if(menuFlags & linkVal)
neonixToggle('subLinks','mnuLinks','',false,'Links', 0);
}
function neonixToggle(itemID,linkID,anchorID,tSwitch,tText, menuValue){// Neonix Toggle Ver 3.0.1 - їurl]www.neonix.netї/url]
if (document.getElementById && navigator.userAgent.indexOf('Opera') == -1){
var itemEL = document.getElementById(itemID);
var linkEL = document.getElementById(linkID);
itemEL.className = itemEL.className == 'TG_visible' ? 'TG_hidden' : 'TG_visible';
if(itemEL.className=='TG_visible') menuFlags+=menuValue;
else menuFlags-= menuValue;
if(!eval(tSwitch)){linkEL.innerHTML = itemEL.className == 'TG_hidden' ? '> ' + tText : '< ' + tText;}
//alert("mv. " + menuValue + " mf. " + menuFlags);
}
if (anchorID.length != 0){;
document.location.href = '#' + anchorID;
}
return;
}
</script>