I have this code:
var cookieorigem = getCookie("Origem")
var cookieactionpay = getCookie("Actionpay")
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
if(cookieorigem == "actionpay" )
{
document.write("<img src=//apypxl.com/ok/6266.png?actionpay="+cookieactionpay+"&apid="<?php echo $orderId;?>"&price="<?php echo $orderValue;?>"&width=1&height=1 />");
}
But it's returning this error when check on mozilla console: SyntaxError: expected expression, got '?'
Anybody can help me?
You're messing up your quote marks. Try this:
document.write("<img src=//apypxl.com/ok/6266.png?actionpay="+cookieactionpay+"&apid=<?php echo $orderId;?>&price=<?php echo $orderValue;?>&width=1&height=1 />");
Your string was being terminated after apid=
so the PHP echo wasn't happening inside the string.
Edit: the resulting script would have looked like this with your original code:
document.write("<img src=//apypxl.com/ok/6266.png?actionpay="+cookieactionpay+"&apid="48"&price="3.99"&width=1&height=1 />");
(And, as mentioned in comments above, this does need to be in a .php
file as well)