checkbox -> linkchanging

wxdqz

New Member
hi!
i want to change a link (by name) by checking a checkbox
i tried it with this, but it doesn't work. has anybody a solution for my problem?

// Changes the last identifier from the from value to the to value
// within the first link of the page.
function replaceLastIdentifier(from, to, linkname) {


//var myLink = document.links[0].href;
var myLink = document.links["change"].href;
var pos1 = myLink.lastIndexOf(from);
alert(pos1 + " " + from + " " + myLink);
if (pos1 > -1) {
myLink = myLink.substring(0, pos1) + to +
myLink.substring(pos1 + from.length);
alert(myLink);
document.links[0].href = myLink;
}
}


// Changes the last /de/ to /en/ if the parameter is true
// or the last /en/ to /de/ if the parameter is false
// This will result in changing the directory to English or German
function setLanguageEnglish(isChecked, checkboxName) {
alert(checkboxName);

if (isChecked) {
// change link to english pdf
replaceLastIdentifier("%2Fde%2F", "%2Fen%2F", checkboxName);
} else {
// change link to german pdf
replaceLastIdentifier("%2Fen%2F", "%2Fde%2F", checkboxName);
}
}
-->
</script>
</head>
<body> <a name="change" id="change"
href=http://www.webdeveloper.com/forum/archive/index.php/"http://xxx.at/Test.html?%2Fde%2Ftarget.pdf">Link</a>

<form name="form1">

<input name="checkEnglish" type="checkbox"
onClick="setLanguageEnglish(this.checked,'change');">
 
Back
Top