Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the query string values in java script and assign to html hidden
Posted

1 solution

Hi,

you can do this by writing code behind code (C# code) in javascript.

JavaScript
// Get value from Query String
var result = '<%= Request.QueryString["queryStingName"]%>';

//then, add value to hidden field
document.getElementsById("hiddenFieldId").value = result;
 
Share this answer
 
Comments
yedhuvamshi 26-Sep-14 9:40am    
Thank u so much.......
But the result value is not passing into hiddenfield or textbox ,please give the code for how to pass the result to textbox or hiddenfield
JR009 26-Sep-14 13:13pm    
Ok following is the code, there are two pages - Page1.aspx and Page2.aspx

Page1.aspx :

<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p> This is PAGE1</p>
<asp:Button ID="btn1" Text="Go To Page2" runat="server" onclick="btn1_Click" />
</div>
</form>
</body>
</html>

Page1.aspx.cs :

protected void btn1_Click(object sender, EventArgs e)
{
Response.Redirect("Page2.aspx?data=test@123");
}

Page2.aspx :

<html>
<head runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
var result = "<%= Request.QueryString["data"] %>";
document.getElementById("hdnField").value = result;
alert(document.getElementById("hdnField").value);
};
</script>
<form id="form1" runat="server">
<div>
<p>
This is PAGE2</p>
<input type="hidden" id="hdnField" />
</div>
</form>
</body>
</html>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900