kekkles4
kekkles4

Reputation: 111

I cannot get php to redirect with onclick()

I have a button in php that will not redirect. Assume the page destination is correct, is anything else wrong with this line?

echo "<button id=\"create\" onclick=\"location.href('/team/teams.php?op=create');\">Create Team</button><br>";

thanks!

Upvotes: 0

Views: 174

Answers (4)

Pieter P.
Pieter P.

Reputation: 109

The javascript syntax is:

location.href = 'url_to_go';

So just delete the bracket and give an equal sign after 'location.href' Here is the code look like:

echo "<button id=\"create\" onclick=\"location.href = '/team/teams.php?op=create';\">Create Team</button><br>";

Upvotes: 0

TejSoft
TejSoft

Reputation: 3315

try

<button id='create' onclick='window.location=\"/team/teams.php?op=create\";'>Create</button>

Upvotes: 0

user4457732
user4457732

Reputation:

Maybe try this?

echo "<button id=\"create\" onclick=\"location.href='/team/teams.php?op=create';\">Create Team</button><br>";

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388446

location.href is not a function, it is a property so

onclick=\"location.href = '/team/teams.php?op=create';\"

In your case, there should be an error in your browser console saying Uncaught TypeError: string is not a function

Upvotes: 1

Related Questions