Not able add multiple option to select

javascript html ajax dynamics-crm

49 просмотра

1 ответ

8 Репутация автора

function successCallback(caRecords) {

        var x = document.getElementById("custAccount"); // select
        var option1 = document.createElement("option"); //options
        //var accno = 0;

     // caRecords i am fetch from MS CRM 
        var count = caRecords[0].results.length;

        if (caRecords != null && count > 0) {
            alert("records are not null");

           for (var i = 0 ; i < count; i++)
           {
               var text = caRecords[0].results[i].new_name;
              // alert(text + "J=" + j);
               option1.text = text;
               option1.value = j;
               x.add(option1);
               j++;

           }
    }   

I got six records and try to insert that values into select as option. It showing last value of my 6 values.

enter image description here

Can anyone help me to improve my code?

Автор: Nagesswara T Источник Размещён: 12.07.2016 04:07

Ответы (1)


0 плюса

5636 Репутация автора

Решение

You can iterate your values like this...

function successCallback(caRecords) {
         var x = document.getElementById("custAccount"); // select
         var options = "";
         var count = caRecords[0].results.length;
         if (caRecords != null && count > 0) {
           alert("records are not null");
           for (var i = 0; i < count; i++) {
             options += "<option value=" + j + ">" + caRecords[0].results[i].new_name + "</option>";
             j++;
           }
           x.innerHTML = options;
         }
Автор: Sankar Размещён: 12.07.2016 04:27
Вопросы из категории :
32x32