Irish SEO,  Marketing & Webmaster Discussion
 

 

Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-10-2006, 01:39 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,923
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default onclick reset class

I have a javascript function which onclick changes the class style to li tag to active, but i am looking to reset the other li's if they are already set as active.

Code:
<script language="JavaScript">
function change(id, newClass) {
 identity=document.getElementById(id);
 identity.className=newClass;
}
</script>
<ul>
<li id="111" class="">
<a href="#" onclick="change('111', 'active');">link</a>
</li>
<li id="222" class="">
<a href="#" onclick="change('222', 'active');">link</a>
</li>
 
</ul>
I am looking for a solution to loop through the li tags and check the id that has been clicked and if <> then chabge class to nothing else change to active.
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Reply With Quote
  #2 (permalink)  
Old 01-10-2006, 05:43 PM
RedCardinal's Avatar
Richard Hearne
 
Join Date: Feb 2006
Posts: 935
RedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to behold
Default

Not sure if this will be any good to you but if I am tracking an event like this I set up a simple cache and record the last clicked element.
Code:
<script language="JavaScript">
var lastClicked = null;
function change(id, newClass) {
 identity=document.getElementById(id);
 if(lastClicked) {
  lastClicked.className = "";
 }
 identity.className=newClass;
 lastClicked = identity;
}
</script>
<ul>
<li id="111" class="">
<a href="#" onclick="change('111', 'active');">link</a>
</li>
<li id="222" class="">
<a href="#" onclick="change('222', 'active');">link</a>
</li>
 
</ul>
If multiple elements can be clicked then you would probably need a second function to cover multiple selected items and you would make lastClicked an array.

Hope it's some use.
__________________
Search Engine Optimisation - Red Cardinal Internet Marketing
Internet Consultant Ireland | Search Engine Optimisation Services
Catering Company Dublin - My sister's handmade canape company!
Reply With Quote
  #3 (permalink)  
Old 01-10-2006, 05:59 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,923
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

That worked like a dream. Thanks man. it was doing my head-in. I try to loop inside the li tags but i coudn't get it to work. My javascript is limited.

Seller - the page I am working on.
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Reply With Quote
  #4 (permalink)  
Old 02-10-2006, 09:27 AM
ph3n0m's Avatar
Webmonkey
Recent Blog: Style form buttons
 
Join Date: Jan 2006
Location: Ireland
Posts: 297
ph3n0m will become famous soon enough
Send a message via AIM to ph3n0m Send a message via MSN to ph3n0m Send a message via Yahoo to ph3n0m Send a message via Skype™ to ph3n0m
Default

uhm that function doesnt appear to be working in Firefox (assuming that when you click an option in the left menu, that options becomes "active" and de-activates the home or previously selected option)
Reply With Quote
  #5 (permalink)  
Old 02-10-2006, 09:33 AM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,923
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

It worked, but I made few changes this morning due to lack of browser history (because of Ajax) and the left menu actually gets refreshed, the reason it doesn't stay active. I am working on it.
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Reply With Quote
  #6 (permalink)  
Old 02-10-2006, 09:45 AM
RedCardinal's Avatar
Richard Hearne
 
Join Date: Feb 2006
Posts: 935
RedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to behold
Default

Quote:
Originally Posted by ph3n0m View Post
uhm that function doesnt appear to be working in Firefox (assuming that when you click an option in the left menu, that options becomes "active" and de-activates the home or previously selected option)
Sorry - I was just giving an example of how you could go about. Never tested or otherwise on any platform.

Hope you get it working Louie, but if you have any problem give me a shout and I will take a look at the actual script.
__________________
Search Engine Optimisation - Red Cardinal Internet Marketing
Internet Consultant Ireland | Search Engine Optimisation Services
Catering Company Dublin - My sister's handmade canape company!
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 02:04 AM.


Powered by: vBulletin Version 3.7.2, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.

Search Engine Friendly URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56