I'm working with a JavaScript code snippet:
window.onload = function() {
document.getElementById("Button1").onclick = function() {
var t1 = document.getElementById("Text1").value;
var t2 = document.getElementById("Text2").value;
document.URL = 'myurl?t1=' + t1 + '&t2' + t2;
}
}
In this code, I am adding t1 and t2 as query parameters. My question is, if I enter data in Textbox1 but not in Textbox2, the URL generated will be
'myurl?t1=' + value of textbox1 + '&t2' + This will be blank;
I want to make this dynamic - meaning if there is no value in Textbox2, I do not want to append the query parameter t2, same goes for t1. Is it possible?