Fill Dropdown and get Strings of Textfield of Website from Go

Hello Guys,

i currently try to do a Fileserver for my Project.
i have to fill a Drop-down-menu with a struct-array, get the name back of the chosen one of the box and have to read the strings inside a textfield of HTML from Go and i dont know how to do that. Pls send me some Code Example cause im new to this language and dont understand much.

Here is my Go-Code:

    //Klimakammer struct
type klimakammer struct {
	name        string
	Hersteller  string
	ip          string
	sollTemp    string
	istTemp     string
	sollFcht    string
	istFcht     string
	kammerstart bool
	kammerstop  bool

//Ct01 Klimakammern erstellen
var Ct01 = klimakammer{"ct01", "weiss", "", "", "", "", "", false, true}

//Kammern - Fill Klimakammer Array
var Kammern = []klimakammer{

func main() {

	fs := http.FileServer(http.Dir("./static"))
	http.Handle("/", fs)

	http.ListenAndServe(":8080", nil)

	http.HandleFunc("/getKammer", func(w http.ResponseWriter, r *http.Request) {
        //The Struct-Array kammern should be passed here to the DropDown


And here is my Func.js Code: -> it’s an onClick Function when you start the program per button

    function fillChoiceBox() {
    var x = document.getElementById("Kammer"); // ID of DropDown
    //Loop for Struct Array
    var option = document.createElement("option");
    option.text = //Every single Chamber/kammer as option like

And that was my previous try, cause of the HandleFunc “/getKammer”

// $.ajax({
//     url: "http://localhost:8080/getKammer",
//     method: "GET",
//     function(data) {
//         var $dropdown = $("#Kammer");
//         $dropdown.append($("<option />").val(data).text(;
//         $("#getKammer").prop('disabled', true);
//         $dropdown.append("<option>hallooo</option>")
//         document.getElementById("status").value = "es funktioniert yee";
//         },
//     });

Encode it to JSON:

package main

import (

type Klimakammer struct {
	Name        string `json:"name"`
	Hersteller  string `json:"hersteller"`
	Ip          string `json:"ip"`
	SollTemp    string `json:"sollTemp"`
	IstTemp     string `json:"istTemp"`
	SollFcht    string `json:"sollFcht"`
	IstFcht     string `json:"istFcht"`
	Kammerstart bool   `json:"kammerstart"`
	Kammerstop  bool   `json:"makkerstop"`

var Ct01 = Klimakammer{"ct01", "weiss", "", "", "", "", "", false, true}

var Kammern = []Klimakammer{

func main() {
	buff, _ := json.Marshal(&Kammern)



	"name": "ct01",
	"hersteller": "weiss",
	"ip": "",
	"sollTemp": "",
	"istTemp": "",
	"sollFcht": "",
	"istFcht": "",
	"kammerstart": false,
	"makkerstop": true


Note that only exported fields can be serialized like this!

and how to get it into the ChoiceBox?

Write the JSON string to the w http.ResponseWriter in the handler func.

Client side JS is out of scope for this forum.

okay thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.