javascript - How to pass the text box value as a part of href - Stack Overflow

I try to pass text box value as a part of link href query string like this :<asp:TextBox ID="tx

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 ?

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 ?

Share Improve this question edited May 17, 2016 at 9:31 Anyname Donotcare asked May 17, 2016 at 9:07 Anyname DonotcareAnyname Donotcare 11.4k72 gold badges231 silver badges408 bronze badges 4
  • This happens cause the "txt_rag" is empty at load. You should use client-side code (ie. Javascript) to update the href property on the client.. – llouk Commented May 17, 2016 at 9:13
  • @llouk : i write a number in the textbox then clicking on the link – Anyname Donotcare Commented May 17, 2016 at 9:15
  • yes, I got it.. "<% %>" are server tags. The code inside it is runs only at load. And if at load the textBox is empty, it will output an empty string inside href. You should try looking for a solution using Javascript on that. – llouk Commented May 17, 2016 at 9:19
  • @llouk Do You have any idea , how to do it client side please? – Anyname Donotcare Commented May 17, 2016 at 9:21
Add a ment  | 

3 Answers 3

Reset to default 3

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.?=" +$(this).val()); }); });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744537027a4579492.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信