mcmuney Posted August 1, 2007 Share Posted August 1, 2007 I'm used to php, but am in need of a java if statement and not sure about syntax. What I need is something like: if current_user_time > 20:00 then colorA=#000000 and colorB=#00000F else colorA=#00000g and colorB=#00000w Then I need to be able to place colorA and B anywhere within the page. Link to comment https://forums.phpfreaks.com/topic/62800-if-statement/ Share on other sites More sharing options...
DeadEvil Posted August 1, 2007 Share Posted August 1, 2007 function preg_replace(array_pattern, array_pattern_replace, my_string){ var new_string = String (my_string); for (i=0; i<array_pattern.length; i++) { var reg_exp= RegExp(array_pattern[i], "gi"); var val_to_replace = array_pattern_replace[i]; new_string = new_string.replace (reg_exp, val_to_replace); return new_string; } } var time = Date(hours+":"+minutes); var formatedDate = preg_replace('\:\\','',time); if (current_user_time > time) { colorA='#000000'; colorB='#00000F'; } else{ colorA='#00000g'; colorB='#00000w'; } or simplest way var time = Date(hours+""+minutes); if (current_user_time > time) { colorA='#000000'; colorB='#00000F'; } else{ colorA='#00000g'; colorB='#00000w'; } Link to comment https://forums.phpfreaks.com/topic/62800-if-statement/#findComment-312637 Share on other sites More sharing options...
mcmuney Posted August 2, 2007 Author Share Posted August 2, 2007 1) Now when I place "colorA" in a table, for example: <table bgcolor=colorA>, how do I do that? I know if php, I simply place <?=$colorA;?>, what's the equivalent in java? 2) What format does "current_user_time" need to be? For example, what would be the format for 9:00PM? Link to comment https://forums.phpfreaks.com/topic/62800-if-statement/#findComment-313475 Share on other sites More sharing options...
DeadEvil Posted August 2, 2007 Share Posted August 2, 2007 the time will be hard coded... <html> <head> <script type="text/javascript"> var time = Date(hours+""+minutes); if (current_user_time == 2100) { colorA='#000000'; colorB='#00000F'; document.getElementById('body').style.bgcolor=colorA; } else{ colorA='#00000g'; colorB='#00000w'; } </script> <body id="body"> </body> </html> Link to comment https://forums.phpfreaks.com/topic/62800-if-statement/#findComment-313718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.