Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Disabled attribute work with hidden

Tags:

jquery

I have a hidden field

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

Now iam applying disabled attribiute through Jquery . Will the Disabled attribute work for hidden fields or it will work only for input type = text

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

if($("#radio_no:checked") && $("#someelement").attr('value')==="abc"){                         
            $("#test1").attr('disabled', true);
            $("#test1").attr('class', 'TextBox');           
}
like image 796
Someone Avatar asked Apr 07 '11 19:04

Someone


1 Answers

It will work fine for hidden fields, preventing their inclusion in a form POST.

The strange myth about having to set the attribute to the string, "disabled", is, well, a myth. Set it to either true or false to be clear. The string "disabled" works because it's a non-empty string, and when cast to boolean it's true. If you were to set it to "no" or "false" or "absolutely not", you'd also disable the input.

edit — to be clear, set the disabled attribute just as in your example, except:

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

edit again — and to those misguided people who disagree with my statement about how (in JavaScript, not in any page source language) one should use true and false for the "disabled" attribute, I would direct you to the appropriate section of the W3C DOM Level 1 spec, where the "disabled" attribute is clearly typed as a boolean, not a string. Once the browser has parsed your pristine, standards-compliant source, be it HTML4, XHTML, HTML5, or whatever, the specific rules for that context no longer matter. We're talking about setting the DOM attribute "disabled" from JavaScript here, so the appropriate standard to reference is the DOM spec.

like image 163
Pointy Avatar answered Oct 22 '22 10:10

Pointy