Felik Skyer
Felik Skyer

Reputation: 29

how to open javascript popup and add a variable to a href using document.write?

my popup link

<a href="javascript:void(0);" onclick="popup('example.com/info?1234', 'PopupWindowCenter')">LINK</a>  

I need add a variable to the popup link

var code01=1234;

document.write("<a href=onclick='popup(example.com/info/+code01+)', 'PopupWindowCenter')">LINK</a>")

sorry for any problem or anything. thanks for all

Upvotes: 0

Views: 181

Answers (2)

f.khantsis
f.khantsis

Reputation: 3550

If you want to support older versions of JS without template literals, try

document.write("<a href=onclick='popup(example.com/info/"+code01+")', 'PopupWindowCenter')">LINK</a>")

Upvotes: 0

guest271314
guest271314

Reputation: 1

You can use template literal

<script>
function popup(a, b) {
  console.log(a, b)
}
</script>
<script>
var code01 = 1234;

document.write(`<a href="#" onclick="popup('example.com/info/${code01}', 'PopupWindowCenter')">LINK</a>`)
</script>

Upvotes: 1

Related Questions