First of all - this question has no answers at Include variable in URL or How can I do string interpolation in JavaScript? I tested many variants from elsewhere before my question here. For example, as advised at Include variable in URL
window.open('http://example.com/?q="+ myname"');
does not work with the script below. A kind of specific wrapping is needed.
So, simplest script
<script type="text/javascript">
function sendquery() {
var myname = "John";
alert(myname);
window.open('http://example.com/?q=(myname)');
}
</script>
<button onclick="sendquery()">Query</button>
Alert perfectly shows variable John. But query sends not variable John but (myname).
Or + myname - if follow other answers.
How to wrap variable to URL query ?