• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

HOw to pass querystring using Javascript?

I was able to click a textbox and url'd to a page. BUt I would like also to attached a querystring.
How would I do that?
1 Solution
Just append the "?VariableName1=Value1&Variable2Name=Value2" to the URL?
Rajar AhmedConsultantCommented:
Are you trying like below ?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.search);
            if (results == null)
                return "";
                return decodeURIComponent(results[1].replace(/\+/g, " "));

        function assignQs(val) {
            //?sample=123 //Sample is the query string parameter.
            var qsName = getParameterByName("sample");
            document.getElementById("lbl").innerHTML = "<br/> Sample :" + qsName + "<br/> textbox value :" + val;
    <form id="form1" runat="server">
    <asp:TextBox ID="txtPassqs" runat="server" onclick="assignQs(this.value);" Text="click me"></asp:TextBox>
    <asp:Label ID="lbl" runat="server"></asp:Label>

Open in new window


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now