0

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 ?

6
  • find('.asp:TextBox') won't work because there is no such thing on the client-side. Add a class to the input and use that. Commented Nov 19, 2014 at 18:06
  • @AntP already tried that, and I have form-control class associated with my textbox which I would like to keep. Commented Nov 19, 2014 at 18:08
  • You can use multiple classes on a single element. If you have tried it, you have not done so properly because it would have solved your problem. You can't select .asp:TextBox because there is no such thing. Commented Nov 19, 2014 at 18:12
  • @AntP I did mention that my Jquery find is probably wrong in my post, so chances are, I did it wrong, thats why I am asking for help :) Commented Nov 19, 2014 at 18:15
  • We have established that what you've posted is wrong but you have said you "already tried" my suggested fix (presumably implying that it didn't work) - without seeing this attempt it is hard to help you further. Commented Nov 19, 2014 at 18:17

1 Answer 1

1

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"]')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.