/    Sign up×
Community /Pin to ProfileBookmark

How to change some HTML via JS…?

Hello all!
Here is my problem code:

[CODE]<img id=”zname” src=”images/dr_eng.jpg” title=”english” alt=”english” [B]onclick=”toggleLang();”[/B]>
<div class=”butoni”>
<table id=”Table_01″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td>
<a href=”” target=”_self”> <!– dobaviam vruzkite –>
<img id=”but1″ src=”images/but1.gif” width=”98″ height=”16″ alt=”Retour au debut”></a></td>
<td>
<a href=”” target=”_self”>
<img id=”but2″ src=”images/but2.gif” width=”95″ height=”16″ alt=”A propos”></a></td>
<td>
<a href=”” target=”_self”>
<img id=”but3″ src=”images/but3.gif” width=”96″ height=”16″ alt=”Reportages”></a></td>
<td>
<a href=”” target=”_self”>
<img id=”but4″ src=”images/but4.gif” width=”96″ height=”16″ alt=””></a></td>
</tr>
</table>
</div>[/CODE]

…well, I’m a beginner :o. The images in the table are buttons(in french). By the function toggleLang(), the images are replaced with other .gif in english which have the same name and postfix “_eng”. Here is the JS code:

[CODE]
function toggleLang(){
var sastoianie=document.getElementById(“zname”);
var tek=sastoianie.title;
var str=”fran&#231;ais”;
var obj_smiana=[‘but1′,’but2′,’but3’]; /*tuk se dobaviat dopulnitelni obekti (id) za smiana na ezika*/
var change_src=””;
var memo=””;

if(tek==”english”){
refresh_etiket:
sastoianie.src=”images/drapeau_francais.jpg”;
sastoianie.title=sastoianie.alt=str;
for(i=0;i<obj_smiana.length;i++){
change_src=document.getElementById(obj_smiana[i]).src;
memo=document.getElementById(obj_smiana[i]);
change_src=change_src.replace(obj_smiana[i],obj_smiana[i]+”_eng”);
memo.src=change_src;
}
}
else{
sastoianie.src=”images/drapeau_anglais.jpg”;
sastoianie.title=sastoianie.alt=”english”;
for(i=0;i<obj_smiana.length;i++){
change_src=document.getElementById(obj_smiana[i]).src;
memo=document.getElementById(obj_smiana[i]);
change_src=change_src.replace(“_eng”,””);
memo.src=change_src;
}
}
}
[/CODE]

This happens as I expect but if the language is switched to english, and if for any reason the page is refreshed, it turns back to french ?.
The browser reads again by the page and there are placed the “french files”.
The problem seems clear but would you help me to solve it, please?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorDec 11.2008 — Save the language preference as cookies. When the page loads, load the appropriate language.
Copy linkTweet thisAlerts:
@kapitanovnauthorDec 12.2008 — Thanks, voidvector, but this solution is not suitable for my case. The page should be initially always in french, and the english settings are used [I]within a session[/I] only if they are requested.

I thought rather about how to use for exemple a flag which remembers that the language has been changed and, at 'refresh', to call automatically the function toggleLang(). I tried by returning a value from the function (0-fr, 1-eng) but it didn't work - when the page reloads the value is forgotten ?.

Please, give any hint
Copy linkTweet thisAlerts:
@voidvectorDec 12.2008 — You can use session cookies. The cookie would expire when user close all his browser window, the next visit would again appear in French.
×

Success!

Help @kapitanovn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...