Results 1 to 5 of 5

Thread: Stylesheet switcher - image menu for selection

  1. #1
    Join Date
    Oct 2006
    Posts
    33
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Stylesheet switcher - image menu for selection

    1) Script Title:
    Stylesheet switcher

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...etswitcher.htm

    3) Describe problem:
    i have created new thread ....please help me
    Instead of using radio button to select stylesheet i want to use menu with images. when i select any color i want to change selected image tansperancy through css.
    Actual code is like below

    Code:
    <div id="colormenu">
    <ul>
    <li><a href="#" type="image" name="color_image" id="blue" onClick="chooseStyle(this.id, 60)"><img src="images/colors_blue.jpg " alt="blue" /></a></li>
    <li><a href="#" type="image" name="color_image" id="orange" onClick="chooseStyle(this.id, 60)"><img src="images/colors_orange.jpg" alt="blue" /></a></li>
    <li><a href="#" type="image" name="color_image" id="red" onClick="chooseStyle(this.id, 60)"><img src="images/colors_red.jpg" alt="red" /></a></li>
    for selected color
    Code:
    <li><a class="current" href="#" type="image" name="color_image" id="red" onClick="chooseStyle(this.id, 60)"><img src="images/colors_red.jpg" alt="red" /></a></li>
    css is
    Code:
    #colormenu a.current img {
    background:#f0f0f0;
    color:#505050;
    border-right:1px solid #505050 ; 
    border-top:1px solid #505050 ; 
    border-bottom:1px solid #505050 ; 
    border-left:1px solid #505050 ; 
    padding:3px 3px 3px 3px; 
    opacity: 1;
    filter: alpha(opacity=100);}
    Problem is i tried using java script to changes class of href. something as below.
    Code:
    function setSelectedStyle(styletitle) {
    elements = document.getElementsByName("color_image")
    var i
    	for (i=0; i < elements.length; i++)
    	{
    		if(elements[i].id==selectedtitle)
    		{
    			alert("item is " + elements[i].id)
    			elements[i].class="current"
    		}
    		else
    		{
    			alert("item is none")
    		}
    	break;
    	}
    }
    Its not working. It does not give any error in javascript console(FF). what went wrong with this code?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Just use the default script and instead of radio buttons, use links like those listed in the "Regular links as the interface:" section from the demo page. These look like so:

    Code:
    <a href="javascript:chooseStyle('none', 60)" checked="checked">Default style</a>
    <a href="javascript:chooseStyle('blue-theme', 60)">Blue theme</a>
    <a href="javascript:chooseStyle('brown-theme', 60)">Brown theme</a>
    Only instead of the text (red in the above) use the images of your choice:

    HTML Code:
    <a href="javascript:chooseStyle('none', 60)" checked="checked"><img src="default.gif" border="0"></a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    I think basically what you're asking is how to dynamically assign the CSS class "current" to the link currently clicked on. Use this code:

    Code:
    <div id="colormenu">
    <ul>
    <li><a href="#" type="image" name="color_image" id="blue" onClick="chooseStyle(this.id, 60); highlightlink(this)"><img src="images/colors_blue.jpg " alt="blue" /></a></li>
    <li><a href="#" type="image" name="color_image" id="orange" onClick="chooseStyle(this.id, 60); highlightlink(this)"><img src="images/colors_orange.jpg" alt="blue" /></a></li>
    <li><a href="#" type="image" name="color_image" id="red" onClick="chooseStyle(this.id, 60); highlightlink(this)"><img src="images/colors_red.jpg" alt="red" /></a></li>
    </div>
    
    <script type="text/javascript">
    
    function highlightlink(selectedlink){
    var menulinks=document.getElementsByTagName("a")
    for (var i=0; i<menulinks.length; i++)
    menulinks[i].className="" //deselect all links
    selectedlink.className="current" //select clicked link
    }
    
    </script>
    As you can see, just call "highlightlink(this)" inside the onClick event handler of each link.

  4. #4
    Join Date
    Oct 2006
    Posts
    33
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for this..but this resets all anchor's class...
    and i also want to use it when page loads to indicate which color is selected ..
    thanks once again
    Last edited by jigarshah; 10-15-2006 at 11:01 AM.

  5. #5
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmmm there's currently no easy way to automatically indicate the link that corresponds to the selected style sheet unfortunately. The script only supports this for radio or selection menu interfaces. It's something I'll have to add to the script down the line.

    Regarding resetting all anchor classes, isn't that what you'd need? By that I mean, in order to assign a class of "current" to the clicked on link, you'd also have to first remove this class from any previously clicked on link. One way is just to remove this class from all links before giving the clicked on link the class again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •