Sunday, December 30, 2012

Get TextBox Value to URL Query String using JavaScript

Lets say we need to get the value from a TextBox and then append it to the URL query string and pass it to another page.

<input type="text" id="name" value="chamara"/>
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="getURL(); return false;">Click Me</asp:LinkButton>

Above would be our HTML code. Now we need to write some JavaScript to get the TextBox value and append it to the URL.

<script type="text/javascript">
function getURL() {
var qun = document.getElementById('name').value;
var URL = "About.aspx?Id=1&Name=" + qun + "";
location.href = URL;

When the user click on the link button he/she will be redirected to the next page with the URL parameters.

No comments:
Write comments
Recommended Posts × +