How to make the difference between unckecked and disabled HTML checkboxes? - html

I'm trying to get the values from some checkboxes. Some are unchecked, some are checked but disabled. In both these cases, no POST data will be sent to the server by the browser.
What I'm wondering, is how can I know that the checkbox was unchecked, or disabled but checked?

You can only check, if a checkbox was checked (send) or not (not send).
If you realy want to know this server side, you can make use of AJAX or set a hidden input before submit.
You can check the state of the checkbox here
document.getElementById("myBox").disabled

Unfortunately the disabled checkbox values are never sent to POST. What I would do is make a small JS code to enable the checkboxes right before the form is sent, or use hidden fields which mimic the checkboxes' values.

Related

How do I make a specific checkbox usable/clickable (not read-only) whilst a form is opened with acFormReadOnly in Microsoft Access?

We've got a checkbox on a form that we'd like to be able to check/uncheck even whilst the form is opened as read-only (it's a sales/product form and when an order has been invoiced, we want to prevent changes).
I know I could add a command button in its place and even make that button look like it's a checkbox with some images, or even set up a key combination to be used instead of the checkbox, but first I'd like to know if it's possible to simply exclude one checkbox from being read-only on a read-only form.
No. You must go the other way around:
Make the form read-write, then disable all controls bound to data fields except this single checkbox.

Can you change preset html form input value?

So if I have a form with a text input, or a select input, I want that box to have a certain value when the page loads. I know you can add,
value="pre defined value"
but when the user erases that and puts in something else, when the form is submitted, is the value that is sent the predefined one or the one that the user changed it to?
The answer to your question is:
The value that is sent is the input that the user typed into the textbox and the value from the select input will be the one you set unless the user uses his browser to change the value(with any developer tools).
On a side note:
If an attacker changes the values then that value will be sent, this is why you must validate all input on server side, and also validate input from hidden, select, checkboxes, etc... elements. Client-side validation is only helpfull to tell the user if he has filled an input with the wrong thing but won't help you against any attacks since they can change the values that are sent with developer tools or a proxy.

HTML: How does the reset button work?

How the reset button (input type="reset") works under the hood?
(I want to extend it so it'll clear the inputs after post in asp.net mvc.)
It makes the browser set the current value of every form control back to its default value (as specified in the HTML, e.g. with the value or selected attributes).
Since it is client side, it cannot be extended with a server side technology like ASP.NET.
If you want to clear inputs after post, then forget reset, just send back the form without any data in it in the HTTP response.
There's a form.reset (docs) method that does the same thing as clicking the form's reset button.
Alternatively you could write some jQuery code that resets the form fields, the topic is covered in this question - Resetting a multi-stage form with jQuery

html: how to uncheck a checked checkbox

I have an html form with a checked checkbox:
<input type=checkbox name="somebox" value="somevalue" checked />
When I get this form, uncheck the checkbox and post the form again, the checkbox is still being passed on together with submitted data. So, unchecking in does nothing finally.
Is there a way to uncheck it? Or may be there is another way to indicate that the checkbox is checked (without using "checked" keyword)?
Thanks in advance
UDP
Finally it was a bug in another place. Checkbox logics is all right. Thanks everyone.
If you have unchecked the checkbox, the "somebox" will not be passed a request parameter.
You must have made a mistake somewhere else.
You could use javascript or jQuery to uncheck it but that's hardley solving the problem.
Sounds like your fighting with viewstate and you'll either need to place this in an update panel, or out side the panel depending on needs, or in your code behind set the checked value of the control before you come back to the page.
get rid of the "checked" property in the control might also be a good start as everytime it comes back from a post it will try to check the box. instead, set it's checked state in the code behind.
If its not checked the name may be passed (often libraries do this when building a request) but the value will not, so if the value of somebox is not somevalue, its not checked.
See How come checkbox state is not always passed along to PHP script?

To change checkbox text or to not change?

I'm having an argument with a co-worker, and I'm trying to convince him that it's a bad idea to change checkbox text (label) according to the checkbox state.
For example, we have a combobox that automatically picks selected value (and is disabled) when checkbox next to it is checked and is enabled when checkbox is cleared. His idea is to show Autoselect when checkbox is checked and Manual select when it's cleared. I'm sure that this will confuse the user as users tend to think that checking a checkbox next to a verb will make it true, only to find that the label has changed to something else.
What is your opinion on this matter?
P.S. I remember reading about changing checkbox text somewhere, in a book or blog article, but can't remember where. It would be great to have this in writing :-)
No need to mess with something that already works.
Changing the label would be horribly confusing and counter-intuitive, especially in the way you describe.
If the label describes the current state ("Manual select"), it will not be clear whether it is necessary to click on the checkbox to achieve the described state (like with a button), or whether it already is in that state.
A checkbox is a simple thing. When it is off, it does A. When it's on, it doesn't do A. The label needs to reflect what it does when it's turned on; it is then perfectly clear what doesn't happen when it is turned off.
If you want to show that the choice is between "Auto select" and "Manual select" then you should either reword your checkbox label or have a radio button:
o Manual Select
* Auto Select
Which isn't really ideal either.
But you shouldn't be changing the text on the label - the user won't remember what it was before and will be confused when it changes.
Personnaly i would say that the label shouldn't change.
From my experience changing the text is confusing, I have the same issue with modal buttons that change their text. It is hard to tell whether pushing the button will turn on the selected state or the text is the selected state.
Tick box text should not change.
Changing the text when the checkbox is checked changes the meaning. If it's checked and the label says Autoselect, I expect the Autoselect option to be enabled. If you uncheck, it's clear that the Autoselect option is NOT enabled. If you change the text to be Manual select whenever the checkbox is cleared I would expect that checking the box would enable the Manual select option. It's way too confusing if the text keeps changing.
You're right, he's wrong.
Checkbox labels should not change. That's part of the way checkboxes work.
See Should “toggle buttons” show what they do or the system status? on UXExchange for an alterantive approach using toggle buttons instead of checkboxes.
The label definitely shouldn't change. It's not only confusing, but it's unnecessary and ugly.
The only way I can think to make it less confusing would be to have the label state in brackets the current state, i.e. "Manual(currently auto)[]".
But that's really just a testiment to how ugly it gets.
Don't mess with what people are used to. Especially when you consider that if you do this, one will always be shown WITH a checkmark, and the other WITHOUT. Really confusing.
In the name of compromise, you COULD use a button instead, which toggles the control back and forth, and changes its value with each click.
Current mode: [Manual]
Still kind of confusing though. As I said, don't mess with what people are used to. It's like if you put a scrollbar on the left of the screen. It'll just mess with peoples' heads.
I would not change the checkbox label... I would have it say "automatic." But, depending on what your controls are actually doing, I might modify the selection in the grayed-out combo-box to reflect that it is now under automatic control.
Then to make the logic go both ways, if while the checkbox was unchecked, the user selected the "automatic" value in the combo-box, the checkbox would then become checked.
Or in another scenario:
If, when the "automatic" checkbox is checked, the automatic logic actually chooses a default value that is in the combo-box, then change the selection in the combo-box to show what the automatic setting actually is. The combo would not be editable, but it could be used to provide information about the actual setting that is being engaged.