DIV elements can be hidden or shown by simply adjusting their display style property as follows: style.display=none : to show the hidden DIV style.display=block : to hide a DIV An example is shown below to demonstrate hide or show div element is shown below: function showhide(id) { if(document.getElementById(id).style.display=="none") { document.getElementById(id).style.display="block"; } else { document.getElementById(id).style.display="none"; } } In the above example the attribute id of the function show hide is the id of the DIV element that we want to hide or show. The hide or show a DIV element id is to be passed from a function call where we want to place it and from where…

Form validation is an important part in the development of a webpage that contains forms. Among the methods and techniques used for form validation, checking if form fields are empty plays an important role as it enables not only the users to identify which fields are compulsory but make the load on the servers lighter as the process validating the form is being done on the client side instead of utilizing the server resources. An example to check if form fields are empty is given below: function isEmpty(formname, fieldname,fieldID) { a=document.forms[formname][fieldname].value; if (a==null || a=="") { document.getElementById(fieldID).innerHTML=fieldname+" Field Empty"; return false; } } The above example takes…

An element can be deleted or removed dynamically by using the removechild attribute. The following function demonstrate the use of the removechild attribute to destroy a div dynamically : function destroydiv(parentDiv, childDiv){ if (childDiv == parentDiv) { alert("The parent div cannot be removed."); } else if (document.getElementById(childDiv)) { var child = document.getElementById(childDiv); var parent = document.getElementById(parentDiv); parent.removeChild(child); } else { alert("Child div has already been removed or does not exist."); return false; } } In the above example childDIV is the DIV id of the DIV element that we want to destroy dynamically. parentdiv is the DIV id of the parent of the child DIV.