0

Im new to jquery, and what im trying to do is add new option to a dropdownlist. Here what I have so far. Could somone explain what im doing wrong?

   <asp:DropDownList ID="drop_company" runat="server"/>

     These dont work:
    $("#drop_company").append($("<option>").val("this"));
    or
    $("#drop_company").append($("<option value="1">Apple</option>"));

1 Answer 1

1

Try,

$("#drop_company").append('<option value="1">Apple</option>');

  1. You were missing $ in ("#drop_company")
  2. You can append it a simple string
  3. You cannot use double quotes inside double quotes without escaping it, else you can use a single quote and inside which you can use double quotes like above.
Sign up to request clarification or add additional context in comments.

1 Comment

the try above: $("#drop_company").append('<option value="1">Apple</option>'); Im not getting any scripting error

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.