Richzilla Posted January 31, 2008 Share Posted January 31, 2008 Hi All, i'm kinda new to javascript and have avoided it for my much prefered php. I'm trying to write a very simple script to rotate our shopping surveys. i want Shopzilla and pricegrabber to appear on different days. I'm getting errors on the following code - <script type="text/javascript"> <!-- var d=new Date(); theDay=d.getDay(); shopzilla="<script language="JavaScript" src="https://evaleu.shopzilla.com/js/pos_xxxxx.js" type="text/javascript"></script>"; pricegrabber="<script type="text/javascript" src="https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=xxxx"></script> <noscript><a href="https://www.pricegrabber.com/rating_merchrev.php?retid=xxxx" target=_blank><img src="https://images.pricegrabber.com/images/mr_noprize.jpg" border="0" width="272" height="238" alt="Merchant Evaluation"></a></noscript>"; switch (theDay) { case 1: document.write(shopzilla) break case 2: document.write(pricegrabber) break case 3: document.write(shopzilla) break case 4: document.write(pricegrabber) break case 5: document.write(shopzilla) break case 6: document.write(pricegrabber) break case 0: document.write(shopzilla) break } //--> </script> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 31, 2008 Share Posted January 31, 2008 try this instead: <script language="javascript"> <!-- var d=new Date(); theDay=d.getDay(); if (theDay == "0") { // Sunday document.write("<script type=\"text/javascrip\" src=\"https://evaleu.shopzilla.com/js/pos_xxxxx.js\" type=\"text/javascript\"></script>"); } if (theDay == "1") { // Monday document.write("<script type=\"text/javascript\" src=\"https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=xxxx\"></script>") } if (theDay == "2") { // Tuesday document.write("<script type=\"text/javascrip\" src=\"https://evaleu.shopzilla.com/js/pos_xxxxx.js\" type=\"text/javascript\"></script>"); } if (theDay == "3") { // Wednesday document.write("<script type=\"text/javascript\" src=\"https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=xxxx\"></script>") } if (theDay == "4") { // Thursday document.write("<script type=\"text/javascrip\" src=\"https://evaleu.shopzilla.com/js/pos_xxxxx.js\" type=\"text/javascript\"></script>"); } if (theDay == "5") { // Friday document.write("<script type=\"text/javascript\" src=\"https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=xxxx\"></script>") } if (theDay == "6") { // Saturday document.write("<script type=\"text/javascrip\" src=\"https://evaleu.shopzilla.com/js/pos_xxxxx.js\" type=\"text/javascript\"></script>"); } //--> </script> <noscript>Add Non-JavaScript Orientated HTML Or Text Here</noscript> Quote Link to comment Share on other sites More sharing options...
nogray Posted January 31, 2008 Share Posted January 31, 2008 First, you need to escape your strings shopzilla="<script language=\"JavaScript\" this works the same way as in PHP second, you can't have </script> in the middle of your script anywhere so you'll need to write it like this ...type=\"text/javascript\"></s"+"cript>"; no point of putting a noscript tag in the middle of your JS <noscript> and everything between it last thing, make sure you don't have any line breaks in your strings var something = "hello world bye world"; is wrong do this instead var sometimg = "hello world\nbye world"; or var something = "hello world\n"; something += "bye world"; Quote Link to comment Share on other sites More sharing options...
Richzilla Posted February 4, 2008 Author Share Posted February 4, 2008 Thanks chaps. Worked perfectly. You work fast!! 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.