Forum Moderators: open

Message Too Old, No Replies

How to dynamicly change text

         

Lookie

11:30 am on Apr 17, 2005 (gmt 0)

10+ Year Member



Hello!

I have a question regarding on how to dynamicly change text inside <a><span id="sometext">text</span></a> tags and changing/adding onClick event to <a> tag.

this is what i have so far :S

function Print() {
var query;
var title;
title = window.location.href;
query = title.indexOf('?');
if (query!= -1) {
if (title.substr(query+1) == 'print=yes') {
document.getElementById("someText").childNodes[0].text = "Print page";
}
}
}
Print();

help or tips appreciated. thanks.

Bernard Marx

3:46 pm on Apr 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<html><head><title>Print</title>
<script type="text/javascript">
window.onload = function()
{
document.getElementById("someText").onclick = Print;
}

function Print()
{
var query = window.location.search.substring(1); /* remove '?' char */
if (query == 'print=yes')
this.childNodes[0].data = "Print page";
return false; /* don't follow link */
}

function Print_alt() /* try this */
{
if( getSearchParam('print')=='yes' )
this.childNodes[0].data = "Print page";
return false;
}

function getSearchParam(name)
{
window.location.search.match(new RegExp('[&?]'+name+'=([^&]*)'));
return decodeURI(RegExp.$1);
}
</script>
</head>
<body>
<a href="#" id="sometext">text</a>
</body>
</html>

Test link to call page:

<a href="test.htm?ooh=ahh&print=yes&dummy=42">GO</a>