Results 1 to 7 of 7

Thread: [Resolved]XHTML 1.1, javaScript, and roll over buttons

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Resolved [Resolved]XHTML 1.1, javaScript, and roll over buttons

    The following code is typically used when someone wants to add rollover buttons on their website (or, atleast what I used to use)
    Code:
    <script type="text/javascript">
    	 if (document.images)
       	{
    	   	  <!-- Home -->
       		  homeon= new Image(139,46);
       		  homeon.src="img/top_nav_home.png";  
         		  homeoff= new Image(139,46);
        		  homeoff.src="img/top_nav_home_over.png";
      	 }
    
    	function un_hover(imgName)
     	{
     		  if (document.images)
        		{
        			  imgOn=eval(imgName + "on.src");
         			 document[imgName].src= imgOn;
       		 }
    	 }
    
    	function hover(imgName)
     	{
       		if (document.images)
       		 {
         			 imgOff=eval(imgName + "off.src");
          			document[imgName].src= imgOff;
        		}
    	 }
    	 </script>
    	<!--Java Script End-->
    And this where the rollover should go:

    Code:
    <a href="index.php" onmouseover="hover('home')" onmouseout="un_hover('home')" >
    <img src="img/top_nav_home.png" class="alpha" name="home" width="139px" height="46px" alt="Home" /></a>
    Now I want to be XHTML 1.1 compliant and I want my code to validate. How do you do rollover buttons without the name attribute since that doesn't exist in XHTML 1.1?
    Last edited by Kasracer; Jun 5th, 2005 at 12:06 AM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XHTML 1.1, javaScript, and roll over buttons

    Get up to date with modern JavaScript techniques, in particular the Document Object Model.

    Also, you should perhaps learn about the CSS :hover pseudo-class, because it makes this stuff a lot simpler.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: XHTML 1.1, javaScript, and roll over buttons

    Quote Originally Posted by CornedBee
    Get up to date with modern JavaScript techniques, in particular the Document Object Model.

    Also, you should perhaps learn about the CSS :hover pseudo-class, because it makes this stuff a lot simpler.
    I know about using :hover, however; as far as I'm away it won't worrk with the CSS PNG haack needed to make IE work with PNGs correctly (which I need).

    I'll search google about the Document Object Model though. thanks

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: XHTML 1.1, javaScript, and roll over buttons

    What you need to do is give each element you want to access and ID attribute with a unique name. You then neet to use the document.getElementById() function to return a reference to the image.

    You can then use the setAttribute() function of the Image element returned by getElementById to set the new image path.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: XHTML 1.1, javaScript, and roll over buttons

    I've been searching google for a while and I cannot seem to find anything about using this technique and creating roll over buttons. I don't know javascript that well (well, I know barely anything in JavaScript. Thankfully I know C++ decently so it's helping).

    Do you have any links to this info?

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: XHTML 1.1, javaScript, and roll over buttons

    Its a relitivly painless task. I have written the follwoing demo, which can be viewed here.
    HTML Code:
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    		<title>Rollover Demo</title>
    		<script type="text/javascript">
    			<!--
    			function changeImage(img, newSrc)
    			{
    				img.setAttribute("src", newSrc);
    			}
    			//-->
    		</script>
    	</head>
    	<body>
    		<p>Use your mouse to demonstrate the image rollover:</p>
    		<p><img src="img/circle1.gif" alt="Rollover Image"
    			onmouseover="changeImage(this, 'img/circle2.gif')"
    			onmouseout="changeImage(this, 'img/circle1.gif')" />
    		</p>
    	</body>
    </html>
    If you want to use the real DOM event model, then you should no use the onmouseover and onmouseout attributes. However, I'm not sure it would work in Internet Explorer then and the above works in both Firefox and IE and also validates.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: XHTML 1.1, javaScript, and roll over buttons

    Thank you!

Posting Permissions

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



Click Here to Expand Forum to Full Width