Add Dropdown Box In Google Site
I have some data in Google sheet. How can i extract the data based on user request as per a dropdown box and generate it in Google Site. The challenges iam faced with. Prob_1- usin
Solution 1:
This is some javascript code to load options into a select box.
function updateSelect(vA)//array of values that go into the drop down or select box
{
varselect = document.getElementById("sel1");
select.options.length = 0;
for(var i=0;i<vA.length;i++)
{
select.options[i] = new Option(vA[i],vA[i]);
}
}
This is html for the select box.
<selectid="sel1"style="width:125px;height:35px;margin:10px 0 10px 0;"><optionvalue=""selected></option></select>
Seem pretty simple to me.
Here's a more complete solution.
Code:
function getSelectOptions()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Options');
var rg=sh.getDataRange();
var vA=rg.getValues();
var options=[];
for(var i=0;i<vA.length;i++)
{
options.push(vA[i][0]);
}
return vA;
}
function showSidebar()
{
var userInterface=HtmlService.createHtmlOutputFromFile('f');
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'The Drop Down with No Options now has options.');
}
f.html
<!DOCTYPE html><html><head><scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script>
$(function() {
$('#txt1').val('');
google.script.run
.withSuccessHandler(updateSelect)
.getSelectOptions();
});
functionupdateSelect(vA)
{
var select = document.getElementById("sel1");
select.options.length = 0;
for(var i=0;i<vA.length;i++)
{
select.options[i] = newOption(vA[i],vA[i]);
}
}
console.log("My code");
</script></head><body><selectid="sel1"style="width:125px;height:35px;margin:10px 0 10px 0;"></select></body></html>
Here's what the sheet named Options
Post a Comment for "Add Dropdown Box In Google Site"