Access Form objects in case of multiple forms

How to access form objects in case of multiple forms, using JavaScript? Assume, we have a form with the id “myform”, then form can be accessed by: var oForm = document.getElementById(‘myform’); This method can only be used only when the <form> tag has an id attribute. Another way to do it without id attribute set […]

How to show or hide text using javascript?

<head> <script> function showhide(id) { if (document.getElementById) { obj = document.getElementById(id); if (obj.style.display == “none”) //check if already hidden, if yes make it appear obj.style.display = “”; else obj.style.display = “none”; //if already appearing then hide here } } </script> </head> <body> <div id=”texthide”> Your text to dispay and hide goes here</div> <a href=”#” onclick=”showhide(‘texthide’); […]

How to access elements having some Class using Javascript?

How to manipulate objects of all tags (suppose div) having some class name? It can be achieved by first fetching all the div tags (or whichever you want) using function getElementsByTagName() and then check their class name using another function className(). It gives us more flexibility apart from getElementsByID() and getElementsByName(). <head> <script type=”text/javascript”> var […]

Button tag inside anchor not working in IE

HTML button tag might not work as expected when put inside anchor tags. <a href=”http://www.expertsguide.info/”><button type=”button”>Click Me to go to Experts Guide</button></a> I works well in Mozilla Firefox but in Internet Explorer (IE) nothing happens on clicking it. Workaround: Put some javascript event inside onclick event handler. Redirect (or open a new window) in javascript […]