Login Register

Disabling and enabling html input tag

Situation: The form submit button is at first disabled. Later, it needs to be enabled.

Problem: setAttribute doesn't work as intended.

Additional clarification: In theory, these two lines should work same:

document.addPage.akcija.disabled=false;
dojo.byId("akcija").setAttribute("disabled", false);

In practice, the first one works, the other doesn't. Here are console printouts:

document.addPage.akcija.disabled=false;

<input id="akcija" type="submit" disabled="disabled" value="Nastavi s prijavom" name="akcija">
<input id="akcija" type="submit" value="Nastavi s prijavom" name="akcija">

dojo.byId("akcija").setAttribute("disabled", false);

<input id="akcija" type="submit" disabled="disabled" value="Nastavi s prijavom" name="akcija">
<input id="akcija" type="submit" disabled="false" value="Nastavi s prijavom" name="akcija">

Ofc, i can use the first one, but i would still like to know how to do it consistently (with dojo.etc). Other reason why i'm curious is because of the explanation here:

http://dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/form-validation-s...

Specificly, this line:

disabled - Boolean: Should this widget respond to user input? In markup, this is specified as "disabled='disabled'", or just "disabled". Use setAttribute("disabled", true/false) to change after creation time.

dijit.byId("akcija").setAttri

dijit.byId("akcija").setAttribute("disabled", true) -- i think is the only issue here.

dojo.byId == domNode
dijit.byId == widget ref
dijit.byId().domNode == widget's domNode

see: http://dojocampus.org/content/2008/05/06/jsid-dijitbyid-and-dojobyid/

Tried that but it doesn't

Tried that but it doesn't work. As you can now see (sorry, didn't notice that the code got parsed :), i'm not dealing with widgets, just regular html elements.

perhaps dojo.attr()?

the dijit attribute setting / getting stuff uses dojo.attr() in most places, perhaps that will help:

dojo.attr("myId","disabled", something);

where "something" is either "disbabled" or "", or maybe true/false ... I'd be curious the results.

You might have to access it directly, not using setAttribute.

...as in:

dojo.byId("myId").disabled = true;

Not all DOMNode properties can be set using setAttribute (thank you, MS).

It works! :)

dojo.byId("akcija").disabled = false;

Thank you very much :)