0
<?php
    $data=SOME_STRING;
    $url="http://SOME_WEBSITE.com/".$data; //$url is a valid website with the addition of data
?>
<input type="button" value="button" onClick="window.open(<?php echo $url;?>)" >

But nothing happens when I click on the button.

It does work when I replace the PHP echo with the precise url string but I want to be able to pass different urls.

  1. Why doesn't it work?
  2. Can you please think about alternative way to achieve this?
2
  • 2
    Maybe you forgot quotes to surround the URL. window.open('<?php echo $url;?>') Commented Sep 4, 2014 at 8:14
  • Whenever running into Javascript problems, first forget about PHP, and just check your Javascript inside your browser. The Element Inspector is your friend there. Commented Sep 4, 2014 at 8:19

1 Answer 1

4

You need quotes:

<input type="button" value="button" onClick="window.open('<?php echo $url;?>')" />
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.