SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    ri
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple javascript function can't handle two parameters... help

    hi-

    i have a simple javascript function that toggles the style of a paragraph from hidden to not-hidden, every time you click the link. i would like to place more hidden information but with a different alignment and format but have it be connected with the other style.... so they both change together. since i want two or more differnet styles to change, they need to have different ids, in my example i call them 45a and 45b and pass both ids to the javascript function which swaps the style from hidden to not-hidden.

    it works fine when there is only 1 parameter... but when i add two i get the javascript console error "ela has no properties."

    everything looks fine to me. can someone please help? here is what my code looks like:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <style type="text/css">
    
    .grayrow {
      background-color: #F3F3F3;
      font-size: 13px;
      margin: 0em .5em 0em .5em;
      padding: 1ex 1ex 1ex 1ex;
    }
    
    
    .grayrow_hidden {
      display: none;
    }
    
    .grayrow_alignright {
      background-color: #F3F3F3;
      font-size: 10px;
      margin: 0em .5em 0em .5em;
      padding: 1ex 1ex 1ex 1ex;
      float: right;
    }
    
    
    .grayrow_alignright_hidden {
      display: none;
    }
    
    </style>
    
    	<script language="Javascript" type="text/javascript">
    	 <!--
    
    		   
    		   function toggle_display (tabname, tabname2) {
    
    				var ela = document.getElementById(tabname);
    				var elb = document.getElementById(tabname2);
    
    
    				if (ela.className.search('_hidden') != -1) {
    					ela.className = ela.className.replace(/_hidden/, '');
    					elb.className = elb.className.replace(/_hidden/, '');
    				}
    				else {
    					ela.className += '_hidden';
    					elb.className += '_hidden';
    				}
    
    		   }
    	 -->
    	</script>
    
    <TITLE> New Document </TITLE>
    
    </HEAD>
    
    <BODY>
    
    <a href="#45" onclick="toggle_display('45a, 45b'); return false"><strong>LINK 1</strong></a>
    
    <p id="45a" class="grayrow_hidden">hidden text that should appear once the link is clicked<br></p>
    
    <p id="45b" class="grayrow_alignright_hidden">Posted:</p>
    
    
    
    
    </BODY>
    </HTML>
    where am i going wrong here?

    thanks alot for any help! sitepoint is great!

  2. #2
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's one of those small things that you never thought it would be.

    Code:
    onclick="toggle_display('45a, 45b');"
    should be:

    Code:
    onclick="toggle_display('45a', '45b');"
    Note the extra single quotes within the parenthasis.
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  3. #3
    SitePoint Addict markchivs's Avatar
    Join Date
    Oct 2004
    Location
    Malvern Hills, UK
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's your function call. Try quotes around both values:

    <code><a href="#45" onclick="toggle_display('45a', '45b'); return false"><strong>LINK 1</strong></a></code>




  4. #4
    SitePoint Addict markchivs's Avatar
    Join Date
    Oct 2004
    Location
    Malvern Hills, UK
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Pip give us newbies a chance man



  5. #5
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Was just about to say I beat you to it, but now you're making me feel bad.

    Sitepoint might have to add functionality to their reply page, saying "Newbie attempting a reply... please wait..."
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  6. #6
    SitePoint Addict markchivs's Avatar
    Join Date
    Oct 2004
    Location
    Malvern Hills, UK
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ha ha ha - alternatively they could put big warning signs saying "Warning Pip is online!! - You may think your posting the first reply"



  7. #7
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And a popular poll it would be, I'm shore.
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.


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
  •