Basically I'm struggling adding PHP into
<a style="cursor:pointer;" onClick="location.href='https://www.example.com/go/'">LINK</a>
My code right now:
<a style="cursor:pointer;" onClick="location.href='https://www.example.com/go/
<?php $randomid = rand(361, 370);
echo '' . $randomid . '&name=john'; ?>
'">Link</a>
But the above doesn't work. When you click, nothing happens.
I have also tried this way:
<?php $randomid = rand(361, 370);
echo '<a style="cursor:pointer;" onClick="location.href='https://www.example.com/go/' . $randomid . '&name=john'">Link</a>'; ?>
But since the javascript contains '' they confict with PHP's html code ''.
How do I solve this?
hrefattribute to link somewhere, like that is supposed to be done, instead of using JavaScript for the same functionality for no apparent reason.doesn't workisn't a useful description. When you run the PHP code, what does the generated link look like? You can examine it in your browser tools to see what it looks like and spot the mistake. But CBroe is right, using JS click to make a link redirect makes no sense when you can just use the link in the normal way..