Anyname Donotcare
Anyname Donotcare

Reputation: 11393

How to pass the text box value as a part of href

I try to pass text box value as a part of link href query string like this :

 <asp:TextBox ID="txt_reg" runat="server"></asp:TextBox>

 <a target="_blank" href="Schedule.aspx?nav=<%=txt_reg.Text %>" >ENTER</a>

But i get no value in nav parameter !

What should i do to pass the textbox value as a part of link ?

Upvotes: 0

Views: 10290

Answers (3)

user3248659
user3248659

Reputation: 71

use following code for setting value to href

$(document).ready(function () { $("#txt_reg").change(function () { $("a").attr("href","test.com?=" +$(this).val()); }); });

Upvotes: 0

llouk
llouk

Reputation: 513

Try something like:

 <asp:TextBox ID="txt_reg" onchange="UpdateLink();" runat="server"></asp:TextBox>

 <a id="myLnk" target="_blank" href="Schedule.aspx?nav=" >ENTER</a>

<script>
function UpdateLink()
{
    var NavValue = document.getElementById("<%=txt_reg.ClientID%>").value;
    document.getElementById("myLnk").href = "Schedule.aspx?nav=" + NavValue;
}
</script>

Upvotes: 1

Proggear
Proggear

Reputation: 712

Try this

<input type=text id=txt_reg />

 <a target="_blank" href="" onclick="this.href='Schedule.aspx?nav='+document.getElementById('txt_reg').value" >ENTER</a>

Upvotes: 3

Related Questions