Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Input Checkbox return 'On' instead of 'True' when submitting form

I have a MVC3 app using Project Awesome (http://awesome.codeplex.com/), but I am getting a weird behaviour on checkboxes. I have the following simple Html within a Modal popup <input type="checkbox" class="check-box" name="IsDeleted">

When I submit the form containing this element, its post value is 'on' instead of the expected 'true' (when element is checked).

Does anybody know why this is? I am assuming there may be some javascript somewhere messing with the form data, but wanted to check whether there isn't some HTML I am missing.

Thanks

like image 434
user460667 Avatar asked Jun 22 '11 14:06

user460667


People also ask

How do I make a checkbox value true?

val( checkbox[0]. checked ? "true" : "false" ); This will set the value of the checkbox to "true" or "false" ( value property is a string) , depending whether it's unchecked or checked .

What value does HTML checkbox return?

Return Value: It returns a string value that represents the value of the value attribute of a input checkbox field.

How do you make a checkbox true in HTML?

The checked attribute is a boolean attribute. When present, it specifies that an <input> element should be pre-selected (checked) when the page loads. The checked attribute can be used with <input type="checkbox"> and <input type="radio"> . The checked attribute can also be set after the page load, with a JavaScript.


2 Answers

Set the checkboxes value attribute to true and you will get true in your post value.

like image 116
Niklas Avatar answered Oct 18 '22 19:10

Niklas


It's browser specific, I suppose, what to send when value is undefined. You need to defined value attribute on your radios/checkboxes to be sure what will be passed back to you. I would suggest value="1"

like image 32
mkilmanas Avatar answered Oct 18 '22 21:10

mkilmanas