0

I was wondering, since HTML5 brings a lot of minimized attributes to the table (and older HTML as well has those), for example autocomplete, another way of writing which could also be autocomplete="autocomplete" for XHTML, and the full version of the attribute.

The same with the disabled or disabled="disabled"

My question to you, is:
How to unset these attributes, how can I stop the form from autocompleting, or making an element not disabled again? Let's say I set via PHP something like disabled="<?php echo(x)?>", if I want to set something to be disabled, as much as I understand, I can put pretty much any value to x, and it will still be disabled? So like, if I type x = "disabled" or x = "randomword", it will behave the same and the element will be disabled. But is there a codeword for actually making it not work? Or how can you achieve this?

For example, I tried:
disabled="false"
disabled="off"
disabled="0"

And they don't seem to work. Maybe I'm not understanding the concept as a whole, and how can you solve this, could someone please tell me, how I can change these values dynamically and easily?

Thanks!

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Arno
  • 356
  • 5
  • 18

3 Answers3

3

simply change disabled="<?php echo(x)?>" to:

<anyTag someAttribut="value"
<?php
  if(condition){
    echo ' disabled="disabled" ';
  }
?>
>//End of Tag

On runtime you can modify those attributes with javascript and treat them like normal, boolean object properties:

document.getElementById('anyElementID').disabled = false;
Daniel
  • 3,541
  • 3
  • 33
  • 46
3

If you set disabled="SOMETHING", your input will be disabled. The only way to do what you want is to not put the disabled attributes in your form.

Instead of disabled="<?php echo(x)?>", you can store disabled='disabled' in a var and print it only if it must be disabled.

Ballantine
  • 338
  • 1
  • 8
1

Attributes like autocomplete and disabled are very different from each other and cannot really be handled as a group.

The autocomplete attribute has two possible values, on and off (case-insensitively), according to HTML5 LC. Other values have been defined in other HTML5 drafts, but this does not affect the issue at hand. It’s a simple attribute with keyword values. The value on is the default. Thus, to prevent autocomplete, you need to set autocomplete=off.

The disabled attribute, along with some other attributes, is defined so that only the presence of the attribute matters, not its value. HTML5 confusingly calls such attributes “Boolean attributes”. This means that an element is not in disabled state if it lacks the disabled attribute. So just omit the attribute altogether.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390