I've got another difficult problem to solve with JavaScript. The string variable comes from outside form input value as you can see below
document.addEventListener('DOMContentLoaded', function() {
var Country = document.getElementById('countr').value;
}, false);
The string address which I need to change is a part of relative href address and will take two different forms.
models/world/some_site.html
or
models/local/some_site.html
The variable Country will be changing as well for example: German, England, France etc.
If I want to replace 'world' or 'local' with Country variable what I need to do is doing something like that
var address = address.split('world').join(Country).split('local').join(Country);
or
var address = address.replace('world', new RegExp(Country, 'g')).replace('local', new RegExp(Country, 'g'));
The result should be look for example like that
models/German/some_site.html
But it doesn't work I don't know why. Any help will be very precious for me.
I discovered that my Country variable don't want to be processed, why? This script not display my variable at all.
document.addEventListener('DOMContentLoaded', function() {
var Country = document.getElementById('cotr').value;
}, false);
document.write(Country);
So this example don't working as well
address.replace(/(local|world)/,Country)
Any help?
My real code looks as below
Indeks.prototype.wyswietl = function(adres)
{
if (typeof adres == 'undefined') adres =
document.forms[this.id].elements['hasla'].value;
if (typeof this.ramka == 'string')
{
var okno =
window.open(adres, this.ramka, 'menubar=yes,toolbar=yes,location=yes,directories=no,status=yes,scrollbars=yes,resizable=yes');
if (okno) okno.focus();
else window.location.href = adres;
}
else this.ramka.location.href =
adres.replace(/(world|local)/,Country);//here I need replacement adres is address
}