Capture disabled checkbox value

0

I have checkboxes disabled, which I check them with a function, but when I check them out or check them out I want to keep their disabled property true, only when I send the data jquery it does not take the selected values, that is, the disableds inputs are not taken into account, how would you do to capture those values?

    
asked by Andress Blend 09.12.2016 в 17:41
source

3 answers

0

Based on the previous question :

  

Firefox, and perhaps other browsers, disable DOM events in form fields that are disabled. Any event that starts in the disabled form field is completely canceled and does not propagate to the DOM tree. Correct me if I'm wrong, but if you click on the deactivated button, the origin of the event is the disabled button and the click event is completely deleted. The browser literally does not know that the button has been clicked, nor does the click event pass. It's like you're clicking on a black hole on the web page.

Because of the above, the method click does not respond in the elements disabled . This can be fixed by wrapping the checkbox in a div:

$("#sub-div").click(function(){
	var type = $(this).children('input').attr("type");
  if ( type === "checkbox" )
  {
    var estado = $(this).children('#dd').prop("checked");
    $(this).children('input').prop( "checked", !estado);
  }
});
#sub-div{
    background-color : #ccc;
    color : #a21;
    display: inline-block;
    border-radius: 6px;
    border: 1px solid #73AD21;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="sub-div">
  <input type="checkbox" name="valor" value="valor" id="dd" disabled > Un valor<br>
</div>
    
answered by 09.12.2016 / 19:18
source
0

I used an old trick, in case someone could help.

$($('input[name="cnSelects"]').prop("disabled",false));
alert($('input[name="cnSelects"]:checked').serialize());
$($('input[name="cnSelects"]').prop("disabled",true));

What I do is put them enabled send the data and then I go back and put them disabled

    
answered by 09.12.2016 в 17:46
0

The prop () method is used to modify Javascript native properties of the elements of a page. In principle, sending a single parameter helps us access the value of a property, that we indicate in the parameter. The other option is used to modify a property and for this we must indicate two parameters, the first would be the property to be modified and the second the value that we want to introduce.

$(elemento).prop("checked");

This would return the value of the Javascript " checked " property, which we surely know, is a Boolean that indicates whether or not a checkbox field is true or false marked.

If we wanted to modify the status of the checkbox , we do the following:

$(elemento).prop("checked", true);

This would make the checkbox marked as confirmed.

And in case the property disabled , it would be as follows:

$(elemento).prop("disabled", true);
    
answered by 09.12.2016 в 17:56