Friday, 13 July 2012



Set unsetattribute using javascript




Username :
Password :


<script>
function setattribute(action)
{
    var obju = document.getElementById('username');
    var objub = document.getElementById('uButton');
   
    var objp = document.getElementById('password');
    var objpb = document.getElementById('pButton');
   
    if(action=='Set Disable'){
        obju.setAttribute('disabled','disabled'); // you can set any attribute of any tags
        objub.setAttribute('onClick','setattribute("unSet Disable");');
        objub.setAttribute('value','click to Enable');
    }else if('unSet Disable'){
        obju.removeAttribute('disabled','disabled'); // you can set any attribute of any tags
        objub.setAttribute('onClick','setattribute("Set Disable");');
        objub.setAttribute('value','click to Disable');
    }
    if(action=='Set Style'){
        objp.setAttribute('style','background-color:#FF0000;'); // you can set any attribute of any tags
        objpb.setAttribute('onClick','setattribute("unSet Style");');
        objpb.setAttribute('value','click to unSet Style');
    }
    else if('unSet Style'){
        objp.removeAttribute('style','background-color:#FF0000;'); // you can set any attribute of any tags
        objpb.setAttribute('onClick','setattribute("Set Style");');
        objpb.setAttribute('value','click to Set Style');
    }
}
</script>
<form name="FormName" id="FormName">
Username : <input type="text" name="username" id="username"><br>

Password : <input type="password" name="password" id="password" ><br>

<input type="button" href="javascript:void(0);" onClick="setattribute('Set Disable');" value="click to Disable" id="uButton">

<input type="button" href="javascript:void(0);" onClick="setattribute('Set Style');" value="click to Set Style" id="pButton">
</form>