The user wants a “readable” description. The database need an “id”. In order to store the “id” I have managed to store the id value in a “data” format using Javascript.
var key = option.dataset.id
field.setAttribute('data-key', key);
The goal is to fetch this “data-id” or “data-key” and pass it to the database. The description that is the normal “value” of a HTML form is already in the database and does not need to be stored again. I can fetch this “data-key” using Javascript.
var inputs = document.querySelectorAll("input[list]");
for (var element of inputs) {
alert(element.dataset.key)
}
This code does only fetch the “description”.
func submit(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
for key, value := range r.PostForm {
fmt.Printf("%s =%s\n", key, value)
}
}
Do you mean the values of the data-id attributes? Those are data attributes that are not present in the form submit. You can’t parse them from the request since the browser does not send them.
You can read them from JavaScript that runs in the browser. You wouldn’t be able to read them from a nodeJS backend, similar to how you can’t read them from a go backend
You can though write JavaScript on the client, that reads those attributes on submitting and adds them to the form data.
A hidden form field is not a Data-Attribute anymore. It’s a form field. You should not trust its value. Though you should not trust any value that would be injected by JS in s pre submit as well.