Buttons with different names?

Does anyone have a JavaScript way to force HTML switches belonging to the same group to have different "name" attributes?

While I see no way, I am working on a website that should work when JS is off, and that would be ideal.

Adding

This is not a requirement, but a preference; there is some consistency in the solution that I am trying to respect regarding the format and name of the parameters that get POSTED. Of course, if necessary, I will tear it apart, but if I can get it to work, I will get this warm fuzzy feeling ...

+4
source share
2 answers

According to the HTML 4.01 specification, the name defines a group, so no, I don’t think there will be non-JavaScript for this.

What are you trying to achieve, so you need radio buttons with different name attributes that are considered part of the same group? Can you use id or class attributes to distinguish them from what you are trying to do?

+5
source

Just stumbled upon this and then solved it for my functionality, I know this is an old thread, but since I would find this information useful 20 minutes ago here, what I did:

keep them grouped with the same name, but distinguish them after they have been sent by checking their value in the column. those.

`

// first radio button if ($_POST['someValue'] == 'someString') { // do something // second radio button } elseif ($_POST['someValue'] == 'anotherString') { // do something else } 

`

hope it will be useful to someone in the future

+1
source

Source: https://habr.com/ru/post/1308842/


All Articles