How to replace ComboBox values on a button click?
I have a button and I want to replace the elements of the combobox.
- <select id="combobox">
- <option value="">Select an option</option>
- <option value="opa">OpA</option>
- <option value="opb">OpBt</option>
- <option value="opc">OpC</option>
- </select>
I want when a user clicks on the button, the elements of combBox changes to a retrieved data from my database.
For instance, change all:
<option value="opa">OpA</option>
<option value="opb">OpBt</option>
<option value="opc">OpC</option>
to:
<option value="IT">IT</option>
<option value="Accounting">Accounting</option>
<option value="HR">HR</option>
I tried .html() but it is not going well.
- function loaddata() {
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "WebService.asmx/GetData",
- data: "{}",
- dataType: "json",
- success: function (data) {
- response(data.d);
- $("#comboox").html();
- },
- error: function (result) {
- alert(result);
- }
- });
- }