LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Need help with a script file (http://www.linuxquestions.org/questions/programming-9/need-help-with-a-script-file-4175431224/)

EODSteven 10-08-2012 07:13 PM

Need help with a script file
 
Why doesn't the swapFE function work?

Code:

addEvent (window, "load", setUp, false);

function addEvent(object, evName, fnName, cap) {
  if (object.attachEvent)
      object.attachEvent("on" + evName, fnName); (Solution.....because of this "on".....)
  else if (object.addEventListener)
      object.addEventListener(evName, fnName, cap);
}
function setUp() {
    var transDoc = document.getElementById("doc");
        var olElem = document.createElement("ol");
                for (var i = 0; i < french.length; i++){
        var newLI = document.createElement("li");
                newLI.innerHTML = french[i];
                newLI.id = i + "phrase";
                newLI.style.cursor = "pointer";
                addEvent(newLI, "onmousedown", swapFE, false); (Solution-change these to exclude on.)
                addEvent(newLI, "onmouseup", swapEF, false);  <--------("mousedown" & "mouseup")-----------
                olElem.appendChild (newLI);
                }
                transDoc.appendChild(olElem);
 }
function swapFE(e) {
        var phrase = event.target || event.srcElement;
                if (phrase.nodeName == "#text")
                phrase = phrase.parentNode;
               
        var phraseNum = parseInt(phrase.id);
                phrase.innerHTML = english[phraseNum];
                phrase.style.color = "rgb(155,102,102)";
                phrase.style.fontstyle = "italic";
}
function swapEF(e) {
        var phrase = event.target || event.srcElement;
                if (phrase.nodeName == "#text")
                phrase = phrase.parentNode;
 
        var phraseNum = parseInt(phrase.id);
                phrase.innerHTML = french[phraseNum];
                phrase.style.color = "rgb(0,0,0)";
                phrase.style.fontstyle = "normal";
}


EODSteven 10-08-2012 07:19 PM

Portion of HTML it goes with...
 
Here's what the script is linked to....

Code:

<div id = "doc">
        <h1>Week 5 Phrases</h1>
        <h2>Press down your mouse button on each phrase to translate</h2>

      </div>
      <address>
        French-English Translation Page
      </address>
  </div>


chrism01 10-08-2012 07:22 PM

I highly recommend you ask the Mods via the Report button to move this to the Programming forum.
The guys there will also ask what lang this is...

EODSteven 10-08-2012 07:27 PM

Request sent...
 
Request has been sent to move this to programming forum...

colucix 10-09-2012 08:24 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 09:37 PM.