CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    170

    OnClick and HREF

    Hi, I am searching for an answer to a similar problem to Javascript not Working Correctly with OnClick and HREF. I have very simple javascript code but the onclick function is never called.


    In the header of my index.html I have

    Code:
    <head>
    <script type="text/javascript"> 
     function togglehide(var ID) 
     {
         var item = document.getElementById(ID);
         if (item) 
         {
             item.className=(item.className=='invisible')?'shown':'invisible';
         }
     }
     
     function article_more(var bodyId, var moreId, var lessId)
     {
         togglehide(bodyId);
         togglehide(moreId);
         togglehide(lessId);
         document.write("<br/>THIS IS A TEST.. DEBUG FUNCTION 1 A 3<br/>");
     }
     </script></head>
    Then, in the body, I have this:

    Code:
    <div class='shown' id='cat1top1art2more'>
        <a href='#' onclick='article_more( cat1top1art2, cat1top1art2more, cat1top1art2less );return false;'>(more...)</a>
    </div>
    
    <div class='invisible' id='cat1top1art2less'>
        <a href='#' onclick='article_more( cat1top1art2, cat1top1art2more, cat1top1art2less );return false;'>(...less)</a>
    </div>
    <div class='invisible' id='cat1top1art2'>
    <p>
    block of text
    </p>
    </div>
    and my css definitions are

    Code:
    .invisible
    { 
        visibility: hidden; 
    }
    .shown
    { 
        visibility: visible; 
    }
    My "(more...)" is displayed, but when I click on it, nothing happens. As you can see, I added a document.write() call to my function just to see if it ever goes there but that text is never written out.
    I am completely baffled by this. I am not sure why the onclick function is never called.
    Last edited by PeejAvery; December 26th, 2010 at 07:29 AM. Reason: Added link

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

Featured