Create an HTML Form Dropdown from a Google Sheet using Google Apps Script

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024
  • In this video, I show how to create an HTML dropdown on google sheets using a list from a google sheet.

ความคิดเห็น • 37

  • @CodeWithCurt
    @CodeWithCurt  4 ปีที่แล้ว +9

    HTML and Javascript Code Below:
    function loadCars() {
    google.script.run.withSuccessHandler(function(ar)
    {
    var carsSelect = document.getElementById("cars");
    console.log(ar);

    let option = document.createElement("option");
    option.value = "";
    option.text = "";
    carsSelect.appendChild(option);

    ar.forEach(function(item, index)
    {
    let option = document.createElement("option");
    option.value = item[1];
    option.text = item[0];
    carsSelect.appendChild(option);
    });

    }).getList();
    };

    function onSelect()
    {
    var carID = document.getElementById("cars").value;
    document.getElementById("carValue").innerHTML = carID;
    };






    loadCars();

  • @CodeWithCurt
    @CodeWithCurt  4 ปีที่แล้ว +3

    Google Apps Script Code in Video Below:
    function getList() {
    var ss= SpreadsheetApp.getActiveSpreadsheet();
    var carSheet = ss.getSheetByName("CARS");
    var getLastRow = carSheet.getLastRow();
    return carSheet.getRange(2, 1, getLastRow - 1, 2).getValues();
    }
    function startForm()
    {
    var form = HtmlService.createHtmlOutputFromFile('dropdownList');
    SpreadsheetApp.getUi().showSidebar(form);
    }
    function addMenu()
    {
    var menu = SpreadsheetApp.getUi().createMenu('Custom');
    menu.addItem('Dropdown Form', 'startForm');
    menu.addToUi();
    }
    function onOpen(e)
    {
    addMenu();
    }

    • @davidgall4185
      @davidgall4185 4 ปีที่แล้ว

      thanks for the code. It still didn't work for me (no items in combobox), BUT - I ran it in Firefox and it worked. Do you know of any computer/browser settings for Chrome that would prevent the code from running. Google seems to be choking on it's own code. thanks again.

    • @CodeWithCurt
      @CodeWithCurt  4 ปีที่แล้ว

      Not sure what would be going on. I run my code through Chrome and Firefox is pretty similar to chrome when it comes to browsers.

    • @amirlatip
      @amirlatip ปีที่แล้ว

      @@davidgall4185 I tried with google also doesn't work. May I know the solution?

  • @newborn7850
    @newborn7850 4 ปีที่แล้ว +2

    I am the first one to Comment, Thanku ,
    My request
    I have a spreadsheet with Fields Name , Age , Photograph.
    How may i import from Spreadsheet and display in HTML page one row at a time , with a next button in html page to display next record of the spread sheet and prev button to display prev record.
    Thanking you

  • @tazulislam2698
    @tazulislam2698 3 ปีที่แล้ว +2

    Sir, Is it possible to include in external html file?

  • @davidgall4185
    @davidgall4185 4 ปีที่แล้ว +1

    Is this code posted anywhere? I've checked my code against the video 10 times over for typos and it still doesn't work. I'm not getting the array to populate the dropdown.
    thanks,

    • @CodeWithCurt
      @CodeWithCurt  4 ปีที่แล้ว

      I posted the code in the comments for both HTML file and GS file. Hope this helps

    • @abelinogomez1224
      @abelinogomez1224 3 ปีที่แล้ว

      @@CodeWithCurt There is no link for the codes

    • @davidmilstein8904
      @davidmilstein8904 3 ปีที่แล้ว

      David, I was going crazy with this one too, but I found the issue which is probably the same one you had, getElementById will prepopulate in the editor as getElementByID capitalizing the D at the end which is not a recognized command in JavaScript, try change it out (all 3 times) and give it a run

  • @djjohnnydott
    @djjohnnydott ปีที่แล้ว

    My use case is similar but I don't have a value pair. I just have a list that I want to show in the dropdown. In the video, he's not clear about whether the HTML select element requires a value pair or not. In fact, he makes it seem optional but I'm thinking maybe it's not. (Like, maybe displaying the value on click is optional but maybe the select element requires value pairs.) Anybody know for sure?

  • @jayasri-ft8040
    @jayasri-ft8040 4 ปีที่แล้ว +1

    Bro, can you guide me the same requirement in web input instated off side of the
    Google sheet.

    • @CodeWithCurt
      @CodeWithCurt  4 ปีที่แล้ว +1

      I have a dropdown in a web app in this video. I hope that is what you were asking for.
      th-cam.com/video/6dDXaTP5Bgs/w-d-xo.html

    • @jayasri-ft8040
      @jayasri-ft8040 4 ปีที่แล้ว

      @@CodeWithCurt yes, exactly what I want. Thank you bro.

  • @ajsantos3739
    @ajsantos3739 2 ปีที่แล้ว

    Hi,
    What about if I wanted to save the value from the "var carID = document.getElementById("cars").value;" into another GSheet through a form that uses those dynamic dropdown options? I tried to to turn the code inside the onSelect() into "document.getElementById("cars").value;" but whenever I submit the form it only records a blank option despite the dropdown showing the dynamic options from the Gsheet.
    I hope you'd see this as I really need help on it.
    Thank you.

  • @jadepereira5292
    @jadepereira5292 ปีที่แล้ว

    This is great. Thanks for the video.
    Would there be anyway to add a step, so when we choose an option in the dropdown we could set that value in a cell in the worksheet?? Almost like the span id option, but only in a cell and not in the sidebar? Thanks

  • @golusingh-qf9yb
    @golusingh-qf9yb 2 ปีที่แล้ว

    Hii...
    I'm making a html form to submit data in DB,
    How can I add the Google sheet columns in select tag, can you give me the relevant code🙂

  • @johnwysham5725
    @johnwysham5725 2 ปีที่แล้ว

    Just marvelous. Very useful, Curt. Exactly the code I am looking for. I also appreciate your relaxed instruction style. Good luck and good wishes.

  • @maxyusupov9508
    @maxyusupov9508 ปีที่แล้ว

    Thanks Curt it was a good instruction, how about to get those values as a columnon a sidebar?

  • @gamontic9567
    @gamontic9567 2 ปีที่แล้ว

    how to create dropdown from a google sheet using javascript

  • @shaitaan0666
    @shaitaan0666 2 ปีที่แล้ว

    hi , i need a html form which is populate dropdown all column integrate from google sheet

  • @omtito8824
    @omtito8824 3 ปีที่แล้ว

    Want to ask at 2:11 seconds how to add "CUSTOM MENU". thank you

  • @sathishkumarc1342
    @sathishkumarc1342 ปีที่แล้ว

    How do to same Thing in Web app instead of Side bar

  • @gonefishing2006
    @gonefishing2006 3 ปีที่แล้ว

    I've watched a bunch of your videos and you usually have a link in the description or codes in the comments. I don't see them this time.

  • @andrewflinn1244
    @andrewflinn1244 3 ปีที่แล้ว

    Where are the links for the code? I still can't find them.

  • @raingo5625
    @raingo5625 ปีที่แล้ว

    how do you make this dependent drop down?

  • @jailbirdx0x
    @jailbirdx0x 3 ปีที่แล้ว

    Just wondering if I can add a .css file to my .html on Google Sheets?

  • @rdlowesinc.9987
    @rdlowesinc.9987 3 ปีที่แล้ว

    Does this work on Mobile devices?

  • @christophergray5416
    @christophergray5416 2 ปีที่แล้ว

    This is super. Thanks.

  • @bishwajitsarkar8873
    @bishwajitsarkar8873 2 ปีที่แล้ว

    Thank you sir.

  • @islakhalmadliy7229
    @islakhalmadliy7229 3 ปีที่แล้ว

    can i copy the code ,,

  • @johnwysham5725
    @johnwysham5725 2 ปีที่แล้ว

    Thanks!

  • @confricami2096
    @confricami2096 ปีที่แล้ว

    Grazie.

  • @suarezasdrubal
    @suarezasdrubal 4 ปีที่แล้ว

    Wonderful! Thank you!

  • @jhicinternational
    @jhicinternational 3 ปีที่แล้ว

    A Million thanks Sir 🙏