Link to home
Start Free TrialLog in
Avatar of netxm
netxmFlag for United States of America

asked on

JavaScript help!

in swapFE() function I need to exchange grench phrase for the english translation. var phrase represents the phrase that was clicked in the document. The whole script has to change text (french for eng and vice-versa) on click.
I'm confused, please help.!!!
function eventSource(e) {
   var IE = document.attachEvent ? true:false;
   var DOM = document.addEventListener ? true: false;
   if (IE) return event.srcElement;
   else if (DOM) return e.currentTarget;
}
function setUpTranslation() {
var phrases = document.getElementsByTagName("p");
for (var i=0; i<phrases.length; i++){
	phrases[i].childNodes[1].innerHTML=french[i];
	
	var phrase = phrases[i].onclick=?
}
}
function swapFE(e){
 phrase = eventSource(e);
 var phrasenum = parseInt(phrases.previousSibling().innerHTML);

Open in new window

Avatar of alain34
alain34
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello netxm,

Can you provide the full listing please?
You are only giving a subset of swapFE...
Also could you tell us where the french[] array is defined?

Regards,

alain34
Avatar of netxm

ASKER

I've made a little progress. I'm not sure that is going work.
this is engfr.js
function eventSource(e) {
   var IE = document.attachEvent ? true:false;
   var DOM = document.addEventListener ? true: false;
   if (IE) return event.srcElement;
   else if (DOM) return e.currentTarget;
  // var phrase = phrases[i].onclick;
  phrase.onclick=phrases[i];
}
function setUpTranslation() {
var phrases = document.getElementsByTagName("p");
for (var i=0; i<phrases.length; i++){
	phrases[i].childNodes[1].innerHTML=french[i];
	}
	
}
 
function swapFE(e){
 var phrase = eventSource(e);
 var phrasenum= parseInt(phrases.previousSibling().innerHTML);
 phrase.innerHTML=english[phrasenum-1];
 phrase.style.color=rgb(155,102,102);
}
 
function swapEF(e){
  phrase = eventSource(e);
  phrase.innerHTML=french[phrasenum-1];
  phrase.style.fontStyle=italic;
  phrase.style.fontcolor=black;
}

Open in new window

Avatar of netxm

ASKER

this is french5.htm
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="french5.js" type="text/javascript"></script>
<script src="engfr.js" type="text/javascript"></script>
</head>
 
<body onload="setUpTranslation()">
<table><tr>
<td class="left">
   <b>French 101</b><br />
   MWF: 9:00-9:50<br />
   Rm. 402 Linton Hall
</td>
<td class="right">
   <b>Prof. Eve Granger</b><br />
   Office: 810 Linton Hall<br />
   Hours: TR: 3:00-4:30
</td>
</tr></table>
 
<h1>Week 5 Phrases:</h1>
<h2>Press down your mouse button on each phrase to translate</h2>
 
<p><span class="pnum"> 1</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 2</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 3</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 4</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 5</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 6</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 7</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 8</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum"> 9</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
<p><span class="pnum">10</span><span class="phrase" onmousedown="swapFE()" onmouseup="swapEF"></span></p>
 
</body>
</html>

Open in new window

Avatar of netxm

ASKER

and this is french5.js
var english=new Array();
english[0]="This hotel isn't far from the Eiffel Tower.";
english[1]="What time does the train arrive?";
english[2]="We have been waiting for the bus for one half-hour.";
english[3]="This meal is delicious";
english[4]="What day is she going to arrive?";
english[5]="We have eleven minutes before the train leaves!";
english[6]="Living in a foreign country is a good experience.";
english[7]="Excuse me! I'm late!";
english[8]="Is this taxi free?";
english[9]="Be careful when you go down the steps.";
 
var french=new Array();
french[0]="Cet h&#244;tel n'est pas loin de la Tour Eiffel.";
french[1]="A quelle heure arrive le train?";
french[2]="Nous attendons l'autobus depuis une demi-heure.";
french[3]="Ce repas est d&#233;licieux";
french[4]="Quel jour va-t-elle arriver?";
french[5]="Nous avons onze minutes avant le d&#233;part du train!";
french[6]="Habiter dans un pays &#233;tranger est une bonne exp&#233;rience.";
french[7]="Excusez-moi! Je suis en retard!";
french[8]="Est-ce que ce taxi est libre?";
french[9]="Faites attention quand vous descendez l'escalier.";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pellep
pellep
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of netxm

ASKER

Thank you, pellep!!!
how to assign the phrase that was clicked in the document to "phrase var"?
Avatar of netxm

ASKER

 phrase.onclick=phrases[I] supposed to represent clicked line...