Dynamic change of link text using java script

Today I was doing some works on java script and html to make a inline virtual keyboard. But I was searching google for a script that can change the link text that means anchor tag’s text dynamically. Opps..I took more that 2 hour to solve it and make it cross browser compatible. So here I want to share the code that I used in my works and the links that helps me.

Suppose you want make  something for each click in a link it’s text will be toggled.

like:

<a href=”url here”>Show</a>

<a href=”url here”>Hide</a>

<a href=”url here”>Show</a>

<a href=”url here”>hide</a>  ….

Let’s here is the code :

<a href=”#” onclick=”showhide();”  id=”linkid”>Show</a>
<script language=”javascript”>

var link = document.getElementById(‘linkid’);
function showhide()
{
if (document.all)
{ //IS IE 4 or 5 or later
if(link.innerText==’Show’)
{
link.innerText=’Hide’;
}
else
{
link.innerText=’Show’;
}
}
//IS NETSCAPE 4 or below
if (document.layers)
{
if(link.innerText==’Show’)
{
link.innerText=’Hide’;
}
else
{
link.innerText=’Show’;
}
//alert(“NETSCAPE 4 or below”);
}
//Mozilla/Netscape6+ and all the other Gecko-based browsers
if (document.getElementById &&!document.all)
{
if(link.firstChild.nodeValue==’Show’)
{
link.firstChild.nodeValue=’Hide’;
}
else
{
link.firstChild.nodeValue=’Show’;
}
//alert(link.firstChild.nodeValue);
//alert(” by id and not all”);

}
}
</script>
This code is compatible with most known browsers..:D

Another way:

function toggleshowhide()
{
var anchors = document.getElementsByTagName(“a”);
for(var i = 0; i < anchors.length; ++i)
{
if(anchors[i].firstChild.data == “Show”)
{
anchors[i].replaceChild(document.createTextNode(“Hide”),
anchors[i].firstChild);
}
else if(anchors[i].firstChild.data == “Hide”)
{
anchors[i].replaceChild(document.createTextNode(“Show”),
anchors[i].firstChild);
}
}
}

java script: window.open function problem in IE

For some days, I am trying to make a popup virtual keyboard for bengali characters for my forum amaderprojukti.com. The problem that I faced and waste so many hours is that it was working in firefox, opera, safari, netscape etc except in IE(Internet explorer).

To make a popup window I used java script some thing like

window.open(‘url to popup’, ‘popup window name’, ‘other parameter’);

Any one can get some help from this link.

The problem I faced that I used the window name with spaces like ‘my window’. It works fine in ‘firefox like browser’ except in IE. When I used the window name ‘mywindow’ (see know space in window name), the code worked in IE too.

I don’t like internet explorer  at all..

Note: I am novice in java script…. :(.