?
Solved

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

Posted on 2007-03-27
10
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 7

Expert Comment

by:Yury Merezhkov
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:Yury Merezhkov
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:Yury Merezhkov
ID: 18801238
Sorry, I mean:

var howManyLinks = 3;
for(var i = 1; i < (howManyLinks + 1); i++) {
   document.getElementById("link" + i).style.fontStyle = "normal";
}
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 

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:Yury Merezhkov
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
 

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:Yury Merezhkov
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:
Yury Merezhkov earned 1000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

777 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