Jump to content

[SOLVED] Rotating Shopping Surveys


Richzilla

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/88736-solved-rotating-shopping-surveys/
Share on other sites

 

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>

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.