473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Applying a style to an onClick event

I have a horizontal navigation. When you click a navigation link that has a child menu, this menu pops out to the side and the parent link gets a background-color applied to it. If the navigation link does not have a child menu, you are taken right to the page, but the active link should still get a background-color applied to it.

However, what is happening is, when I click on a childless link, a parent link above it gets the background applied to it instead of the link that was actually clicked. This happens in both IE and FF.

The navigation functions and the onClick functions correctly. However, the style is being applied in the wrong place.

Here's the javascript:
Expand|Select|Wrap|Line Numbers
  1. function secondarymenuToggle(name,id) {
  2.     var eArray = document.getElementsByTagName('DIV');
  3.     var ele = document.getElementById(id);
  4.  
  5.     for (i = 0; i < eArray.length; i++)
  6.     {
  7.         if (eArray[i].getAttribute('name') == name)
  8.             eArray[i].className="SecondaryMenu";        
  9.     }
  10.  
  11.     if (ele != undefined)
  12.         ele.className="SecondaryMenuActive";    
  13.  
  14. }
  15.  
Here's the php where it is being put into the page:

[PHP]
$link_before = "<a href=\"".$location_var.$option_link."&cbc=1&uspid= ".$option_id."\" CLASS=\"SecondaryMenu\">";
$link_after = "</a>";
$onclick = "onclick=\"displayMenu('".$option_id."', '".$divString."');\"";
$onclick_toggle = "onclick=\"secondarymenuToggle('levelone','levelon e".$levelone_counter."');secondarymenuToggle('leve ltwo','')\"";

echo "<tr $onclick>\n";
echo "<td><div class=\"SecondaryMenu\" $onclick_toggle name=\"levelone\" id=\"levelone".$levelone_counter."\">";
echo "<div class=\"SecondaryMenu\" >".$link_before.$image_var.$link_after.$link_befor e.$option_display_value.$link_after."</div>";
[/PHP]

It seems that maybe the loop is getting mixed up somewhere? I've troubleshot this quite a bit and am not really sure what is happening. If you would like me to better explain the problem, let me know. Unfortunately it is not publicly accessible.
Nov 18 '08 #1
6 1921
acoder
16,027 Expert Mod 8TB
Can you post the client-side HTML code as rendered in the browser. It makes it easier to debug.
Nov 19 '08 #2
Dormilich
8,658 Expert Mod 8TB
maybe I can persuade you to use a CSS driven menu....? (I didn't understand your navigation system)

regards

PS: maybe just the topic you want: "Keeping navigation current with PHP"
Nov 19 '08 #3
Can you post the client-side HTML code as rendered in the browser. It makes it easier to debug.
Sure and I was able to troubleshoot down to what the actual problem is. Here's the output:

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2. <td>
  3. <div class="SecondaryMenuActive" 
  4. onclick="secondarymenuToggle('levelone','levelone5');
  5. secondarymenuToggle('leveltwo','')" name="levelone" id="levelone5">
  6. <div class="SecondaryMenu">Reports</div></td>
  7. </tr>
  8.  
  9. <tr>
  10. <td>
  11. <div class="SecondaryMenu" 
  12. onclick="secondarymenuToggle('levelone','levelone5');
  13. secondarymenuToggle('leveltwo','')" name="levelone" id="levelone6">
  14. <div class="SecondaryMenu">
  15. <a href="../charge" class="SecondaryMenu">Calls</a>
  16. </div></td>
  17. </tr>
  18.  
The first link works properly and has a second menu that pops out. The second link is not working properly and is just a link.

As you can see, they both say "levelone5", which is wrong. The second one should say "levelone6". The numbers are correct up until this link. The "levelone5" is coming from a variable on the ID that simply adds one each time in the loop ($counter++).

I'm still not really sure why it gets stuck at this point.
Nov 19 '08 #4
acoder
16,027 Expert Mod 8TB
I may have to move this to the PHP forum since it looks like the problem is in your PHP code.

Can you post the rest of the relevant PHP code, e.g. the loop, the counter, etc.
Nov 20 '08 #5
Can you post the rest of the relevant PHP code, e.g. the loop, the counter, etc.
I thought I did post the loop in the for statement of my javascript, no?
Expand|Select|Wrap|Line Numbers
  1. function secondarymenuToggle(name,id) {
  2.            var eArray = document.getElementsByTagName('DIV');
  3.            var ele = document.getElementById(id);
  4.  
  5.           for (i = 0; i < eArray.length; i++)
  6.            {
  7.               if (eArray[i].getAttribute('name') == name)
  8.                   eArray[i].className="SecondaryMenu";        
  9.           }
  10.  
  11.           if (ele != undefined)
  12.              ele.className="SecondaryMenuActive";    
  13.       }
  14.  
PHP-wise, the only counter-related things I have are:
Expand|Select|Wrap|Line Numbers
  1. $levelone_counter = 1;
  2. $levelone_counter++;
  3.  
Nov 20 '08 #6
acoder
16,027 Expert Mod 8TB
I meant the loop in the PHP code.
Nov 20 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jeff Anderson | last post by:
Is there a style for a select option's "selected" color? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1...
5
by: Ben | last post by:
I have a form for data entry which is in a table. I have a select box to enter a customer name, which takes it's options from the customer database. I have a button to add a new customer. What I...
2
by: Raed Sawalha | last post by:
I have the following table in ascx , when I click the button the table style not showing in the popup , it is ONLY showing on the page not in the popup...WHY? <TABLE style="BACKGROUND:...
29
by: Richard Lionheart | last post by:
Hi All, I've taken the advice of a few people and managed to cobble together an HTML 4.01 Strict-compliant document (according to the W3C Validation Service), but the way I try to pass a...
4
by: jnag | last post by:
Hello, Through an onClick() event, I have an inline function to change the font size of the page (actually, I need to do this for the entire website). I have this defined in the header.cfm file...
3
by: jnag | last post by:
I am trying to implement font changer, where I have links on the banner of the site and when the user clicks on the links, the font size of the page has to change. I tried...
4
by: datvong | last post by:
IE does not change the cursor immediately after a style.cursor is set. In the following sample, I have 2 divs, one inside another. The inner has a cursor of crosshair, outer a hand. If I click...
1
by: Constantine AI | last post by:
Here is the situation i am currently trying to update a sales order using PHP and javascript. When you click on the edit button it brings you a new site page with existing sales order details within....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.