LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-08-2012, 09:00 PM   #16
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
1st Java file


1st Java file...
Code:
/*
   

   Filename: engfr.js


   Function List:

   addEvent(object, evName, fnName, cap)
      Adds an event hander to object where evName is the name of the event,
      fnName is the function assigned to the event, and cap indicates whether
      event handler occurs during the capture phase (true) or bubbling
      phase (false)

   setUp()
      Insert the current week's french phrases into document and set up
      event handlers for the phrases.

   swapFE(phrase, pnum)
      Changes a French phrase to the English version of that phrase.

   swapEF(phrase, pnum)
      Changes an English phrase ot the Frech version of that phrase.

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

function addEvent(object, evName, fnName, cap) {
   if (object.attachEvent)
       object.attachEvent("on" + evName, fnName);
   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);
		addEvent(newLI, "onmouseup", swapEF, false);
		olElem.appendChild (newLI);
		}
		transDoc.appendChild(olElem);
 }
function swapFE(event) {
	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(event) {
	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";
}
 
Old 10-08-2012, 09:01 PM   #17
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
2nd Java file

second java file....

Code:
/*
  

   Filename: french5.js


   Variable List:
   french
      Contains an array of 10 english phrases

   english
      Contains an array of 10 French translations
*/

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.";
 
Old 10-08-2012, 09:03 PM   #18
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
CSS

Style Sheet.....

Code:
*                  {margin: 0px; padding: 0px}
#page              {width: 700px; border: 1px solid rgb(155, 102, 102)}

#head              {width: 700px; color: white; font-size: 14px;
                    font-family: Arial, Helvetica, sans-serif;
                    background-color: rgb(155, 102, 102);
                    padding: 10px 0px}
#rightHead         {float: right; margin-right: 10px}
#leftHead          {margin-left: 10px}

#links             {clear: both; width: 120px; float: left; 
                    border-right: 1px solid rgb(155, 102, 102);
                    list-style-type: none; margin-left: 15px;
                    font-size: 12px; padding-bottom: 10px}
#links a           {display: block; text-decoration: none; width: 100%;
                    color: black}
#links a:hover     {background-color: rgb(155, 102, 102); color: white}

#links .newgroup   {margin-top: 5px; margin-left: -10px}

#doc               {float: left}
#doc ol            {margin-left: 45px; margin-top: 15px}

h1, h2             {font-family: Arial, Helvetica, sans-serif; 
                    padding: 0px 10px}
p                  {padding: 0px 10px; margin: 2px}
.pnum              {margin-right: 5px; text-align: right; width: 30px; 
                    border: 1px solid rgb(155,102,102); padding-right: 2px;
                    color: white; background-color: rgb(155,102,102)}
.phrase            {font-style: italic; cursor: pointer}
h1                 {font-size: 18px; margin: 20px 0px 5px 0px}
h2                 {font-size: 12px; font-weight: normal; margin: 5px}
address            {clear: left; text-align: center; font-style: normal;
                    background-color: rgb(155, 102, 102); color: white;
                    font-family: Arial, Helvetica, sans-serif}
 
Old 10-08-2012, 09:05 PM   #19
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
Ok!

That's all of them!
 
Old 10-08-2012, 11:11 PM   #20
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,667

Rep: Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440
Fixed it.

setUp() in engfr.js should be this:

Code:
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, "mousedown", swapFE, false);
		addEvent(newLI, "mouseup", swapEF, false);
		olElem.appendChild (newLI);
		}
		transDoc.appendChild(olElem);
 }
The difference is that the event names are now "mousedown" and "mouseup", not "onmousedown and "onmouseup". The reason is that this is what you have in addEvent:

Code:
function addEvent(object, evName, fnName, cap) {
   if (object.attachEvent)
       object.attachEvent("on" + evName, fnName);
   else if (object.addEventListener)
       object.addEventListener(evName, fnName, cap);
}
addEvent already prepends "on" to "evName", so you ended up adding event listeners to "ononmouseup" and "ononmousedown". That's why it wasn't working.

BTW, that's a sweet idea for a language quiz.

Last edited by dugan; 10-08-2012 at 11:46 PM.
 
1 members found this post helpful.
Old 10-09-2012, 04:31 AM   #21
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
Sorry I went to bed...Thank you!!!!!

Here's the page out of my book...That's ridiculous that they expect students to figure that out.

Code:
 Core Events
The general event attributes are part of the specifications for HTML and XHTML. They
apply to almost all page elements.

Attribute Description HTML XHTML
onclick The mouse button is clicked. 4.0 1.0
ondblclick The mouse button is double-clicked. 4.0 1.0
onkeydown A key is pressed down. 4.0 1.0
onkeypress A key is initially pressed. 4.0 1.0
onkeyup A key is released. 4.0 1.0
onmousedown The mouse button is pressed down. 4.0 1.0
onmousemove The mouse pointer is moved within the element’s boundaries. 4.0 1.0
onmouseout The mouse pointer is moved out of the element’s boundaries. 4.0 1.0
onmouseover The mouse pointer hovers over the element. 4.0 1.0
onmouseup The mouse button is released. 4.0 1.0
I'm glad the world has smarter folks than the one who wrote my book!
Gonna try to take out the "on" and see if that works.......Nope....it will only work the way you wrote it!

Last edited by EODSteven; 10-09-2012 at 04:37 AM. Reason: additional info
 
Old 10-09-2012, 09:23 AM   #22
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,667

Rep: Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440
If isn't for a course, and you're allowed to choose your book, then you should look for a different one. The "on" event properties are deprecated. They only became common because they were the only option in some old versions of Internet Explorer. The W3C standard way to do it is with addEventListner("mouseup"), which also works in current version of Internet Explorer.
 
Old 10-09-2012, 09:48 AM   #23
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
Last Tutorial

My Book was the 4th edition and I have seen that they are already in the 7th edition. That was my last tutorial anyway so I'm moving on to A+ Guide to managing and maintaining your PC...CompTia certification course!. I'm looking forward to the "nuts & bolts" of the PC, something I'm much well suited for. I was a Robotic tech for years till I had to get a defibrillator installed and had to move away from strong magnetic feilds. Again Dugan, thank you very much and it was so nice to meet a "nice" Canadian! . Take care! P.S. How do you install the cool Tags at the end of your Posts?

Last edited by EODSteven; 10-09-2012 at 09:53 AM. Reason: Question
 
Old 10-09-2012, 10:05 AM   #24
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 177

Original Poster
Rep: Reputation: 3
Signature...

I think I found it...Signature.....Gonna edit that...
 
  


Reply

Tags
java, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding internal IP address without proxy, both Java and Java script enabled studpenguin Linux - Security 12 01-08-2011 08:39 PM
Hiding internal IP address without proxy, both Java and Java script enabled studpenguin Linux - Networking 1 01-02-2011 02:50 AM
Need a Java Applet to utilize Java Script Functions circuit_girl Programming 3 04-11-2009 09:55 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration