Set unsetattribute using javascript
<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>
Hey this is good BRO.... Keep posting
ReplyDeleteOne thing i cant understand "javascript:void(0);"
ReplyDeletewhat is this....?
Sometimes, you may need to call some JavaSript from within a link. Normally, when you click a link, the browser loads a new page (or refreshes the same page).
DeleteThis might not always be desirable. For example, you might only want to dynamically update a form field when the user clicks a link.
To prevent the load from refreshing, you could use the JavaScript void() function and pass a parameter of 0 (zero).