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. Quote Link to comment 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'; } Quote Link to comment 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? Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.