Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox 'off' value without JavaScript

Tags:

html

checkbox

Does anyone have a no JavaScript way to make HTML checkbox still submit a value? As in if you check it the form submission will include a value A but if it is uncheck it still contains a value B?

While I figure there isn't any way, I'm working on a site which needs to still be function when JS is off, and this would be ideal.

like image 324
Richard JP Le Guen Avatar asked Dec 23 '22 03:12

Richard JP Le Guen


1 Answers

HTML checkboxes aren't supposed to work that way. If you check the checkbox, the definied parameter name=value pair will be sent. If you uncheck it, it will not be sent. In the server side you just have to check the presence of the parameter name (or value in case of multiple checkboxes in a named group) in the parameter map and handle accordingly. If present, then it's checked. If absent, then it's not checked. Simple as that. You already know the "unchecked value" in the server side.

like image 104
BalusC Avatar answered Jan 14 '23 18:01

BalusC