简体   繁体   中英

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 ?

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>

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>

use following code for setting value to href

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM