Reputation:
I have a PHP echo statement in which I create an HTML button element, and within that button element I'd like to set the onclick attribute to the location.href function to redirect to another page when the user clicks the button. But I can't seem to get this working, nothing happens when the button is clicked. I think it has to do with the multitude of single and double quotes but I'm not sure. Here's my latest attempt, but I've tried escaping the inner quotes a number of ways.
echo "Commissioner Admin</th><td><button type='button' id='adddirectoradmin' value='adddirectoradmin' width='75' onclick=\"location.href('http://some-url')\">Add</button></td>";
Upvotes: 0
Views: 1904
Reputation: 906
try this:
echo "Commissioner Admin</th><td><button type='button' id='adddirectoradmin' value='adddirectoradmin' width='75' onclick='". location.href('http://some-url')."'>Add</button></td>";
Upvotes: 0
Reputation: 220136
location.href
is not a function. Your quotes are all OK.
Your problem is that you're calling location.href
instead of just assigning it a new value:
onclick="location.href = 'http://some-url'"
Upvotes: 3