S
S
Spooky 20202021-10-15 23:26:44
JavaScript
Spooky 2020, 2021-10-15 23:26:44

How to uniquely identify marks from different inputs (radio, checkbox) scattered around the site?

There are various forms (independent) in which by setting the desired flag it is noted, for example, the "type" of something.
What I need - if, for example, in the first form the choice of a certain type is determined by a radio button with one id,
and in the second form the same type is selected by a checkbox, naturally with a different id - then how to make sure
that the same type (value, identifier )? To edit the code with handles, adding the necessary identifier for types to value?

For now, I’m thinking about how to simply collect the id of different inputs in a collection and associate a common type with them:

const types = new Map([
  [input_id_100,   typeA],
  [input_id_500,   typeA],
  [chekbox_id_foo, typeB],
  [check_bar_box,  typeB],
  [input_id42,     typeB]
])

how is this done properly?

PS
For constant identifiers in JS, as I understand it, global Symbols should be used, and not string names?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-10-16
@Aetae

Nowadays, the correct answer is: use frameworks, or at least for forms. It will assemble everything for you. Doing everything by hand is just asking for bugs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question