I create a list in Sharepoint which has 3 columns Title,Label and SiteUrl as per business requirement label want to show text and Url will be the value using javascript.
Need add this HTML into file
<div id="divVariationLabel">
<select id="drpVariationlbl" id="drpVariationlbl" onchange="redirectSite()" />
</div>
Create JS file add this below script into it then add this file reference into the HTML file.
/***************************************************************************
* Name : CreateDrodown.js *
* Descritption : This is the javascript file for creatig dropdown using List data *
***************************************************************************/
var countryData = [];
(function ($) {
$(document).ready(function () {
// Ensure that the SP.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(CreateDropdown, 'SP.js');
});
/***************************************************************
* Function : CreateDropdown *
* Descritption : This function is used to fill the Dropdown *
***************************************************************
function CreateDropdown() {
var listName = "Variation Label";
jQuery.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/Items",
type: "GET",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
if (data.d.results.length > 0) {
var results = data.d.results;
$.each(results, function (index, dataLabels) {
var temp = [];
var PlantID = dataLabels.Id;
var countryName = dataLabels.Title;
var countryLabel = dataLabels.Label;
var countrySiteUrl = dataLabels.SiteUrl;
//temp.push('<div class="maptitle">' + dataPlants.Title + '</div>' + plantOfficeAddress);
temp.push(countryName);
temp.push(countryLabel);
temp.push(countrySiteUrl);
countryData.push(temp);
});
for (var subArr in countryData) {
$('<option />', { value: countryData[subArr][2].Url, text: countryData[subArr][0], variationlabel: countryData[subArr][1] }).appendTo('#drpVariationlbl');
}
}
}
});
}
})(jQuery);
Need add this HTML into file
<div id="divVariationLabel">
<select id="drpVariationlbl" id="drpVariationlbl" onchange="redirectSite()" />
</div>
Create JS file add this below script into it then add this file reference into the HTML file.
/***************************************************************************
* Name : CreateDrodown.js *
* Descritption : This is the javascript file for creatig dropdown using List data *
***************************************************************************/
var countryData = [];
(function ($) {
$(document).ready(function () {
// Ensure that the SP.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(CreateDropdown, 'SP.js');
});
/***************************************************************
* Function : CreateDropdown *
* Descritption : This function is used to fill the Dropdown *
***************************************************************
function CreateDropdown() {
var listName = "Variation Label";
jQuery.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/Items",
type: "GET",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
if (data.d.results.length > 0) {
var results = data.d.results;
$.each(results, function (index, dataLabels) {
var temp = [];
var PlantID = dataLabels.Id;
var countryName = dataLabels.Title;
var countryLabel = dataLabels.Label;
var countrySiteUrl = dataLabels.SiteUrl;
//temp.push('<div class="maptitle">' + dataPlants.Title + '</div>' + plantOfficeAddress);
temp.push(countryName);
temp.push(countryLabel);
temp.push(countrySiteUrl);
countryData.push(temp);
});
for (var subArr in countryData) {
$('<option />', { value: countryData[subArr][2].Url, text: countryData[subArr][0], variationlabel: countryData[subArr][1] }).appendTo('#drpVariationlbl');
}
}
}
});
}
})(jQuery);
No comments:
Post a Comment