SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot jooles's Avatar
    Join Date
    Jun 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small Javascript Problem

    Code:
    <script type="text/javascript">
    
    function viewSpecials(mode){
    			
    if(mode=="todays"){
    document.getElementById("specialsMenu").innerHTML="todays | <a href=javascript:viewSpecials('all')>all</a>"
    }
    				
    if(mode="all"){
    document.getElementById("specialsMenu").innerHTML="<a href=javascript:viewSpecials('todays')>todays</a> | all"
    }
    
    }
    
    </script>
    
    <div id=specialsMenu>
    todays | <a href=javascript:viewSpecials('all')>all</a>
    </div>
    I don't know why my code isn't working. After the javascript outputs a link with an a href=javascript the link doesn't work.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After the javascript outputs a link with an a href=javascript
    Never do that. Instead, put an onclick attribute in the <a> tag, for the href use a page that you want people who have javascript disabled to see, and return false from the function assigned to the onclick in order to cancel the click for people who have js enabled.


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
  •