Does the Disabled attribute work with hidden

I have a hidden field

<input type = 'hidden' name = "test1" id = "test1" value ="<?php echo $val ?>" > 

Now Yam applies disabled attribute via jQuery. Will the Disabled attribute work for hidden fields or will it only work for input type = text

 $('#test1').attr('disabled','disabled'); if($("#radio_no:checked") && $("#someelement").attr('value')==="abc"){ $("#test1").attr('disabled', true); $("#test1").attr('class', 'TextBox'); } 
+6
source share
2 answers

It works great for hidden fields, preventing them from being included in the POST form.

The strange myth about setting an attribute to a string, "disabled", is, well, a myth. Set it to true or false . The "disabled" line works because it is a non-empty line, and when you click on boolean it is true . If you were to set it to "no" or "false" or "absolutely no", you would also disable the input.

edit - to be clear, set the disabled attribute in the same way as in your example, except:

 $('#test1').attr('disabled', true); 

change again - and to those unfaithful people who do not agree with my expression on how (in JavaScript , and not in any source language of the page), you need to use true and false for the "disabled" attribute, I would send you the corresponding section the W3C DOM Level 1 specification, where the "disabled" attribute is explicitly entered as a logical rather than a string. After the browser analyzes your untouched, standards-compliant source, be it HTML4, XHTML, HTML5 or something else, the specific rules for this context no longer matter. We are talking about setting the DOM attribute to β€œdisabled” from JavaScript here, so the DOM specification is the appropriate standard for reference.

+9
source

it will work, you can apply any attribute that you like, but it does not make sense to do this.

0
source

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


All Articles