0

I had written the below code to bind a values of List column into html drop-down. Can any one help in knowing what's wrong in my below code.

<script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript"> </script>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"> </script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js "></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.js"></script>

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
 <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
 <link rel="stylesheet" href="/resources/demos/style.css">

<body>
<table>
<tr>
 <td class="fontsize">Months:</td>
 <td>
       <select id="drbfunction" class="select">
       <option selected="selected">Select</option>
       </select>
 </td>
</tr>
<tr>
 <td class="fontsize"><br>Programes:</td>
 <td><br>
       <select id="drbprogrames" class="select">
       <option selected="selected">Select</option>

</tr>
</table>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js "></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getItems);


function getItems() {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/GetByTitle('Tabletop%20Sessions')/items?Select=Title”,
type: “GET”,
headers: {
“accept”: “application/json;odata=verbose”,
},
success: function (data) {
var result  = data.d.results;  // Get the results
var selectInput  = ”;       //create a variable for structure  a HTML to append select control
for(var i=0; i<result.length; i++)
{
var selectVal= result[i].Title;   // get the results of Title column into array
selectInput  = ‘<option value=’+ selectVal +’>’+ selectVal +'</option>’;  // pass the array of  values
$(‘#drbprogrames’).append(selectInput);
}
},
error: function (error) {
alert(JSON.stringify(error));

}
});
}
</script>
  • have you looked at the answers in your previous question? – Arsalan Adam Khatri Mar 1 '18 at 6:26
  • @MSA are you getting any error message. If yes, please share it.. – Rohit Waghela Mar 1 '18 at 6:30
0

Refer below code :

function getItems() {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Tabletop%20Sessions')/items?Select=Title",
        type: "GET",
        headers: {
            "accept": "application / json;odata = verbose",
        },
        success: function(data) {
            var response = data.d.results;
            $.each(response, function(key, value){
                $("#drbprogrames").append('<option value="' + value + '">' + value +'</option>');
            });
        },
        error: function(error) {
            alert(JSON.stringify(error));
        }
    });
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.