How do I get the phrase number from the phrase object using the parseInt() function? I tried to create the function within the swapFE function in var phrasenum below but it did not work. I think my values are wrong. What should I put there instead? Any help would be greatly appreciated. Thanks in advance! The following is the french phrase number (1-10 or in JavaScript 0-9) and the french an english phrases to be used:
> 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ô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élicieux";
french[4]="Quel jour va-t-elle arriver?";
french[5]="Nous avons onze minutes avant le départ du train!";
french[6]="Habiter dans un pays étranger est une bonne expé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.";
Here are the functions I am working on:
function setUpTranslation() {
var phrases = document.getElementsByTagName("p");
for (i = 0; i<phrases.length; i++) {
phrases[i].number = i;
phrases[i].childNodes[1].innerHTML = french[i];
phrases[i].childNodes[1].onmousedown = function() { swapFE(event); };
}
}
function swapFE(e) {
var phrase = e.srcElement;
var phrasenum = parseInt(phrase[1].childNodes[1].innerText);
alert("French Number = "+phrasenum+"Phrase = "+phrase.childNodes[1]);
}
This is the answer I came up with and it worked. See var phrasenum. Thanks for all your help guys!