Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-27
10
Medium Priority
?
401 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: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

610 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