Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys. I have use Dropdownlist . I try change text in Dropdownlist , but i can not. Seem it losts some data .

i.e : in Dropdownlist i have three data: AREA1,AREA2,AREA3, it load from ajax .
JavaScript
<select id="cbo_area"></select>
   function cb_area() {
                $.ajax(
                {
                    type: "POST",
                    url: "../BUS/WebService.asmx/LIST_AREA", //// get list all area
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $("#cbo_area").html('');
                        $.each($.parseJSON(data.d), function (idx, obj) {
                            $("#cbo_area").append(
                                '<option value="' + obj.AREA_ID + '">' + obj.AREA_NAME + '</option>');
                        });
                    },
                    error: function (data) {
                        alert("HTML Error Load Combo");
                    }
                });
            }

Ok, in my table , i click at row then click edit button, it will show data from row to Dropdownlist. it work but it only show one data , in this case "AREA2" (lost AREA1 and AREA3 in Dropdown) , i try click another row , i get that right , in this case "AREA3" (lost AREA1 nad AREA2 in Dropdown), etc...
JavaScript
$('#bt_edit').click(function (e) {
                    var DTO = {
                        'area_id': area_id_temp
                    };
                    $.ajax(
                    {
                        type: "POST",
                        url: "../BUS/WebService.asmx/AREA_NAME",  /// get name area follow id
                        data: JSON.stringify(DTO),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            $("#cbo_area").html('');
                           //cb_area(); // no work , it will loop data two times
                           /// it only will one data in Dropdownlist
                            $.each($.parseJSON(data.d), function (idx, obj) {
                                $("#cbo_area").append(
                                    '<option value="' + obj.AREA_ID + '">' + obj.AREA_NAME + '</option>');
                            });
                           //cb_area();  // no work, it will load wrong data
                        },
                        error: function (data) {
                            alert("HTML Error Load Edit");
                        }
                    });
});


I want to click a row in table , Dropdownlist will change text from row and concurrent with fields remaining data. i.e : when i click a row have "AREA1" , Dropdownlist text will change "AREA1" and more "AREA2" , "AREA3". Please give me some advice about this .
As I said above, I can load data into dropdownlist via cb_area function. I want to click on the row in the tables, data dropdownlist will change and additional the remaining fields.

Example: Dropdownlist alway have three text data : AREA1, AREA2, AREA3.

My table

HTML
1   ABC       123      AREA1

2   EFG        456     AREA2

3   IJK          789     AREA1

4   EFG         011    AREA3


I will click a row 2 , then click edit button . In here text in dropdownlist need to change AREA2, AREA1,AREA3 . , If i click a row 4, then click edit button, text in dropdownlist need to change AREA3,AREA1,AREA2 ,...etc

This means that text in dropdownlist will change according to the data of the line on the table, besides it must also other data
Best Regards.
Thank you.
Posted
Comments
ramyajaya 15-Apr-15 21:21pm    
In your ajax, you hqve to set the text of that drop down list .

$("#cbo_area").value=
obj.AREA_ID;


Add this line this will set the value of the select.

P.S:
you are adding options tag to your dropdownlist am not surr why do you do this if you already know your possible datas, think about it.
headshot9x 16-Apr-15 21:59pm    
Dear ramyajaya.
I try and not work.
Anyone ideas ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900