I'm trying to use Javascript to display two possible sets of content. One set of content is served to an affiliate, whose traffic has "?hop=fuzzphil" in the URL. I'm using PHP to grab the parameter, then passing it into JavaScript and trying to use an in-else statement to determine which hidden div to display. Beneath the JS code are two hidden divs with different names; I want to use JS to trigger the display of either section after a time delay.
Here's what my code looks like right now:
Code:
<?php $affiliateid = $_REQUEST['hop']; ?>
<script type="text/javascript">
var hopid="<?php echo $affiliateid; ?>";
if (hopid == "fuzzphil") {
function showBuyLink() {
document.getElementById("buttonphilippe").style.display = "inline";
setTimeout("showBuyLink()", 5000);
}
}
else {
function showBuyLink() {
document.getElementById("buylink").style.display = "inline";
setTimeout("showBuyLink()", 1000);
}
}
</script>
Beneath the code are two divs with "display: none" and the id set to either "buylink" or "buttonphilippe." I've tested the delay code independently and it works, but something in the if-else is breaking it I think. I've also tested just putting the PHP hop ID into the variable and it document.writes just fine, so I'm not sure what's going on.
1. if you are using php for grabbing the paramentr why not to use it for displaying the apropriate content?
2. if grabbing the part of the url is the only reason for using php you don't need to use php at all
use [code]YOUR CODE GOES HERE[/code] or burn in Hell
1) We're using Visual Website Optimizer for split testing and it's interfering with the code. I think having dynamically generated code is more difficult when you're also dynamically generating the content. We tried with PHP first and it didn't work very well.
2) It's beyond my JS skills. I found this bit of code online:
Code:
function get(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
var hopid=get('foo');
But it didn't work. I don't really understand it enough to troubleshoot it.
Anyway, I already tested using PHP to assign the variable and that part of the code works fine. I know it's not the most efficient way of doing things, but I just want it to work, I don't really care about it being efficient. Any idea why the code as it is isn't working? The variable assignment part is fine ;/
Just one more quick question - How do I make it so the content displays after a certain period of time? For example, say I wanted it to display in 30 seconds. I tried to adapt the old code to your code, but it didn't work ;/
Here's what your code looks like on my site right now:
Basically say "If hop=fuzzphil, display X content after 30 seconds, otherwise display Y content after 30 seconds." Everything you wrote works perfectly, THANK YOU. Just hoping to get this one last thing figured out. Really appreciate the help.
Bookmarks