The flag is off without JavaScript

Does anyone have a JavaScript way to make the HTML checkbox still send the value? As with if you check it, the form view will contain the value A, but if it unchecks it still contains the value B?

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

+4
source share
3 answers

HTML flags should not work this way. If you check the box, a pair of defined parameters name = value will be sent. If you remove it, it will not be sent. On the server side, you just need to check for the parameter name (or value in the case of several flags in the named group) in the parameter map and process it accordingly. If he is present, he is checked. If absent, then it is not checked. Just like that. You already know the "unverified value" on the server side.

+7
source

Perhaps you can do this by having a hidden form element with the same name . However, different browsers may relate to the priority, which is sent (if the checkbox is selected) in different ways, so at best it is a hacker solution.

+4
source

As I worked, one of these problems was to set up a hidden form element that included all the names flags separated by a comma. Then, on the server side, I just blew up this line and checked which checkboxes were turned on and off. However, it was still hacked, but at that time I was not familiar with JavaScripts, so I ended up doing it. Given the revision of this at present.

Hope this helps someone.

0
source

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


All Articles