How to handle Querystring in JavaScript?
Posted
by Wondering
on Stack Overflow
See other posts from Stack Overflow
or by Wondering
Published on 2010-06-02T08:28:17Z
Indexed on
2010/06/02
8:33 UTC
Read the original article
Hit count: 157
JavaScript
Hi All, I have a js code:
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;
}
}
Here i am adding t1,t2 as query param..now my question is lets say i have entered some data in Textbox1 but not in textbox2, in that case the url I am getting is
'myurl?t1=' + value of textbox1 + '&t2' + This will be blank;
I want to make it dynamic, i.e.if there is not value in Textbox2 then I dont want to append queryparam t2, same goes for t1 also..isit possible?
© Stack Overflow or respective owner