NickyTheWrench NickyTheWrench - 2 months ago 10
HTML Question

Inserting a javascript variable into onclick window.open

I'm trying to insert a JavaScript variable into an href, and make it open in a new window.

Here is my code:

<a href="https://example.com" onclick="window.open(this.href+'?VALUE='+testVALUE;, '_blank'); return false;">Click Here</a>

<script>
var testVALUE = '1AB56';
</script>


The URL should look like this:
https://example.com?VALUE=1AB56

Can someone please tell me where I'm going wrong?
Thanks for your help!

Answer

There's a ; in the middle of the argument you pass to window.open. Just after testVALUE

Comments