• 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?
0
zachvaldez
Asked:
zachvaldez
1 Solution
 
tlaytonCommented:
Just append the "?VariableName1=Value1&Variable2Name=Value2" to the URL?
0
 
Rajar AhmedConsultantCommented:
Are you trying like below ?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
        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 "";
            else
                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;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txtPassqs" runat="server" onclick="assignQs(this.value);" Text="click me"></asp:TextBox>
    <asp:Label ID="lbl" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Open in new window

0

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