Solved

change link style onmousedown, revert to previous style onmousedown of new link

Posted on 2007-03-27
10
361 Views
Last Modified: 2013-11-19
In the menu below, I would like the style of each link to change to italics onmousedown. I know I can implement this by using onmousedown="this.style.fontStyle=italic", but once a client clicks on another link the menu, how do I revert the link that was previous clicked to normal whilst the most recently clicked link switches to italics? The menu is constant. I don't move to new pages, I just load new content into a layer. Here's the menu code:
            <p>
                <a href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page1.html')">
                Developer</a>&nbsp;&nbsp;
            <a href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page2.html');>Current Project</a>&nbsp;&nbsp;
            <a href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page3.html')">Conferences Db</a></p>
0
Comment
Question by:GessWurker
  • 6
  • 4
10 Comments
 
LVL 7

Expert Comment

by:RealSnaD
ID: 18801177
What you can do is put an id on each link.

<p>
   <a id="link1" href="javascript:void(0)" class="menu"
       onmousedown="pageManager('load_page','content/page1.html')">
        Developer</a>&nbsp;&nbsp;
   <a id="link2" href="javascript:void(0)" class="menu"
       onmousedown="pageManager('load_page','content/page2.html');>Current             Project</a>&nbsp;&nbsp;
   <a id="link3" href="javascript:void(0)" class="menu"
onmousedown="pageManager('load_page','content/page3.html')">Conferences Db</a></p>
0
 
LVL 7

Expert Comment

by:RealSnaD
ID: 18801205
Oh sorry, accidentally clicked submit.

Ok so you put id on each link as shown above and then in your pageManager function  at the top do the following:

var i;
var howManyLinks = 3;
for(i = 1; i < (howManyLinks - 1); i++) {
   document.getElementById("link" + i).style.fontStyle = "normal";
}

0
 
LVL 7

Expert Comment

by:RealSnaD
ID: 18801238
Sorry, I mean:

var howManyLinks = 3;
for(var i = 1; i < (howManyLinks + 1); i++) {
   document.getElementById("link" + i).style.fontStyle = "normal";
}
0
 

Author Comment

by:GessWurker
ID: 18801658
RealSnaD: It seems your code has the effect of changing all the links to normal, even the one that was just clicked. I want the one that was just clicked to remain italicized.
0
 
LVL 7

Expert Comment

by:RealSnaD
ID: 18801710
Take a look at this code. It does what you want:

<script language="JavaScript">
      function pageManager(obj) {
            var howManyLinks = 3;
            for(var i = 1; i < (howManyLinks + 1); i++) {
               document.getElementById("link" + i).style.fontStyle = "normal";
            }
            obj.style.fontStyle = "italic";
      }
</script>
<p>
      <a id="link1" href="javascript:void(0)" class="menu"
      onmousedown="pageManager(this)">Developer</a>&nbsp;&nbsp;
      <a id="link2" href="javascript:void(0)" class="menu"
      onmousedown="pageManager(this)">Current Project</a>&nbsp;&nbsp;
      <a id="link3" href="javascript:void(0)" class="menu"
      onmousedown="pageManager(this)">Conferences Db</a>
</p>

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:GessWurker
ID: 18801801
No. doesn't work in my context. Here's the pagemanager code with your modifications. Unfortunately, the modifications make the code, which is also run onload, fail.

Here's the broken code:
function pageManager(obj) {
  var args = pageManager.arguments;
  switch(args[0]) {
    case "load_page" :
      content.top = (w3dom) ? 60  + "px": 60;
      if(ie4) {
        document.frames["frameData"].document.location = args[1];
      }
      if(w3dom) {
        document.getElementById("frameData").src = args[1];
      }
      if(ns4) {
        content.load(args[1],page.width);
      }
    break;
    case "page_is_loaded" :
      if(ns4) {
        sizeAnimator(content,page.width,content.htm.height);
      }
      clearTimeout(page_timer);
      page_timer = setTimeout("pageManager('display_page')",300);
    break;
    case "display_page" :
      if(ie4) {
        content.htm.innerHTML = document.frames['frameData'].document.body.innerHTML;
      } else if(w3dom) {
        content.htm.innerHTML = window.frames.frameData.window.document.getElementById('body').innerHTML;
      }
    break;
  }
var howManyLinks = 3;
for(var i = 1; i < (howManyLinks + 1); i++) {
   document.getElementById("link" + i).style.fontStyle = "normal";
}
obj.style.fontStyle = "italic";
}

Here's a sample page: that uses the code:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   
<head>
<title> Dynamic HTML External Loading </title>
 <script type="text/javascript" src="overlib/overlib.js"><!-- overLIB (c) Erik Bosrup --></script>
<script type="text/javascript" src="externalLoader.js">
</script>
<link rel="stylesheet" type="text/css" href="content/example4.css" />
<meta http-equiv="imagetoolbar" content="no" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
    <body onload="defineObjects()">
    <div id="overDiv" style="position:absolute; visibility:hidden; z-index:2;"></div>
        <div id="contentLYR" style="text-align:center"></div>
        <iframe frameborder="0" width="100" height="100" id="frameData" name="frameData" scrolling="No" src=""></iframe>
        <div id="Layer1" class="c1" style="text-align:center">
            <p>
                <a id="link1" href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page1.html')">
                Tom - Developer</a>&nbsp;&nbsp;<a  id="link2" href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page2.html');this.style.fontStyle='italic'">Current Project</a>&nbsp;&nbsp;
            <a id="link3" href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page3.html')">Conferences Db</a>&nbsp;&nbsp;
            <a id="link4" href="javascript:void(0)" class="menu"
                onmousedown="pageManager('load_page','content/page4.html')">Intranet Catalog</a>
                        </p>
    </div>
    </body>
</html>
0
 

Author Comment

by:GessWurker
ID: 18801983
Then I tried adding a separate function

function italicizeMe(obj){
var howManyLinks = 4;
for(var i = 1; i < (howManyLinks + 1); i++) {
   document.getElementById("link" + i).style.fontStyle = "normal";
}
obj.style.fontStyle = "italic";
}

and altering adding an onmousedown event like so:

onmousedown="pageManager('load_page','content/page4.html');italicizeMe(obj)

No luck. Didn't work
0
 
LVL 7

Expert Comment

by:RealSnaD
ID: 18802002
First of all, don't forget to change

var howManyLinks = 3;

to the amount of links you have. In the example you posted it would be 4:


var howManyLinks = 4;

Secondly, function call should look like this for each link (you can change the parameters but don't touch the last one which is THIS):

onmousedown="pageManager('load_page','content/page1.html', this)"

Finally, change

function pageManager(obj) {

to whatever you had before but add obj as the last parameter.

Then it will work.
0
 
LVL 7

Accepted Solution

by:
RealSnaD earned 250 total points
ID: 18802013
As a separate function you almost right:

Change

onmousedown="pageManager('load_page','content/page4.html');italicizeMe(obj)"

to

onmousedown = "pageManager('load_page','content/page4.html');italicizeMe(this)"
0
 

Author Comment

by:GessWurker
ID: 18802033
Eureka! Thanks. Points to you!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now