Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically enable/disable form inputs from js in ie6

Status
Not open for further replies.

homefish

MIS
May 23, 2003
11
0
0
GB
Although Microsoft have made the [tt]isDisabled[/tt] attribute of DOM Nodes of type [tt]INPUT[/tt] read-only, there is a way to enable or disable a form input dynamically - at least in ie6.

The technique uses textual substitution on the [tt]outerHTML[/tt] attribute of the node in order to lock it. This technique does not work to unlock the cell but, fortunately, it does work on the [tt]innerHTML[/tt] attribute of the parent element.

The following code works for me in ie6.

Code:
<HTML><HEAD>
    <script type="text/javascript" language="JavaScript">
        function disable(oid) {
            var o = document.getElementById( oid );
            o.outerHTML = o.outerHTML.replace(
                /INPUT/i, 'INPUT disabled ' );
        }
        function enable(oid) {
            var o = document.getElementById( oid );
            o.parentElement.innerHTML = o.parentElement.innerHTML.replace(
                /\s+disabled\s+(=\s+\S+\s+)?/i, ' ' );
        }
    </script>
</HEAD><BODY><FORM>
    <input id="ID00" type="text" value="00"> <br />
    <input type="button" value="disable" onclick="disable('ID00')" />
    <input type="button" value="enable" onclick="enable('ID00')" />
</FORM>
</BODY></HTML>
.

Yours,


fish.
 
Looks like Vorlon bio-technology to me... what's wrong with "disabled" property (DOM1/HTML 4.0)?

Code:
    <script type="text/javascript" language="JavaScript">
    function enadisable( sID, bEnable )
    {		document.getElementById( sID ).disabled  = !bEnable;
    }
    </script>
...    
<FORM>
    <input id="ID00" type="text" value="00"> <br />
    <input type="button" value="disable" onclick="enadisable('ID00', false );" />
    <input type="button" value="enable" onclick="enadisable('ID00', true );" />
</FORM>
 
>> "Looks like Vorlon bio-technology to me... what's wrong with "disabled" property"

my thoughts exactly [lol]

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Yup - using "disabled" always works for me, too

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top