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 ( == “none”) //check if already hidden, if yes make it appear = “”; else = “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=””><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 […]

Parse XML or HTML

Here’s a simple XML parser, with DOM Object, which can fetch values digging deep but in a few lines of code. It uses namespace functinality(XPATH). The XML document must have defined namespaces. <?php $xml = <<<EOT <?xml version=”1.0″ encoding=”UTF-8″?> <entry xmlns=”” xmlns:other=”” > <id>uYG7-sPwjFg</id> <published>2009-05-17T18:29:31.000Z</published> </entry> EOT; $doc = new DOMDocument; $doc->loadXML($xml); $xpath = DOMXPath($doc); […]

HTTP Authentication in URL not working in IE

IE (Internet Explorer) doesn’t work with user names and passwords in Web site addresses URLs (HTTP/S). Though, IE versions 3.0 to 6.0 support this. The following URL syntax may not work in Internet Explorer or in Windows Explorer, http(s):// Reason: Such URL syntax is used to automatically send username/password to a Web site which requires […]

CSS margin style property not working

There’s a weird characteristic of margin style property. Instead of adding two margins together, a web browser applies the larger of the two margins. This is called colliding margins. For example, if there an unordered list tag above a paragraph tag. The list tag is assigned with the bottom margin of 20 pixels and the […]