Reputation: 811
I am trying to set value of textbox with drop down list using jquery, but cant figure out how to find current textbox.
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="row" id="formValidator">
<div class="col-sm-6">
<div class="form-group" id="contractGroup">
<label for="inputContract" class="col-sm-5 control-label">Contract Type <b>*</b></label>
<div class="col-sm-7">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Full-time</a></li>
<li><a href="#">Part-time</a></li>
</ul>
</div>
<asp:TextBox runat="server" type="text" class="form-control" ID="inputContract" placeholder="Full time, Part time"></asp:TextBox>
</div>
</div>
</div>
</div>
</div>
</asp:Content>
Jquery function
$(document).on('click', '.dropdown-menu li a', function() {
$(this).parent().parent().parent().find('.asp:TextBox').val($(this).html());
});
Which is probably wrong, I attempted to use closest()
as well, but to no avail , from my search online I saw people are using made up classes for elements they are trying to find, is that necessary ?
Upvotes: 0
Views: 48
Reputation: 3110
Close.. You have to go up one more parent and look for input type of text:
$(this).parent().parent().parent().parent().find('input[type="text"]')
Upvotes: 1