user1005497
user1005497

Reputation:

How to set the selected value of a (ajax) combobox with jquery

I have a gridview with row selection which should set the page's elements value by the selected id... When I press the row, I want my (ajax-editable)combobox to change its value(index) by the data turning from async page. I tried almost everything... Please need urgent help... :(

function VeriYaz(id) {
        $.ajax({
            type: "GET",
            url: "VeriAl.aspx",
            data: "id=" + id,
            async: false,
            success: function (data) {
                var urunler = data.split('|');
                document.getElementById('<%= cmbkategori.ClientID %>').value = stripHTML1(urunler[0]);}
        });
        }

Upvotes: 0

Views: 7078

Answers (2)

Ravi Makadia
Ravi Makadia

Reputation: 17

Ajax ComboBox having the Hidden value..

You can do only validation from that hidden parameter..

$('#<%= id-of-combobox.ClientID%>_HiddenField').val();

Upvotes: 0

James Johnson
James Johnson

Reputation: 46047

You can use the val([value]) function to set the selected value with jQuery:

$("#<%=DropDownList1.ClientID%>").val("1");

EDIT

If you want to set the selected value based on the data returning from your AJAX call, you should be able to do this:

$("#<%=DropDownList1.ClientID%>").val(stripHTML1(urunler[0]));  

To set the selected item by the text, you can do this:

$("#<%=DropDownList1.ClientID%> option:contains(" + stripHTML1(urunler[0]) + ")").attr("selected", "selected");

EDIT

It sounds like you're using the AJAX Toolkit ComboBox, in which case you can try something like this:

$find("<%=ComboBox1.ClientID%>").get_textBoxControl().value = stripHTML1(urunler[0]);

Upvotes: 1

Related Questions