SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Michigan
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why doesn't this else statement execute?

    I've got this code that works perfectly on the first click of a td -- the class is changed correctly. However, I cannot get the class to change on a second click (that's what the else statement is there for). It's probably some idiotic logic on my part - maybe you can help?

    Code:
    function initClicks() {
        // get all tds inside table with id 'schedule':
        var nav = document.getElementById('schedule');
        var tds = nav.getElementsByTagName('td');
        // for each of these tds, add a onclick event handler:
        for (var i=0;i<tds.length;i++){
            tds[i].onclick = clicked;
        }
    }
    
    function clicked() {
        // if the class is 'standard', change to 'selected'.
        if(this.className='standard'){
        this.className='selected';
        // if the class isn't 'standard', change it to 'standard'.
        // I don't know why this doesn't work.
        }else {
        this.className='standard';
        }
    }

  2. #2
    SitePoint Zealot tristanm's Avatar
    Join Date
    Jan 2005
    Location
    Hampshire, UK
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    if(this.className='standard')
    should be

    HTML Code:
    if(this.className=='standard')
    Your currently assigning the value every time the function is called which will always return true.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Michigan
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh duhhhhhh---- thanks a lot!

  4. #4
    SitePoint Zealot tristanm's Avatar
    Join Date
    Jan 2005
    Location
    Hampshire, UK
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MattH
    Oh duhhhhhh---- thanks a lot!
    No worries.

    Easy mistake to make when you've been staring at a piece of code for a while (I do it all the time). Just needed a fresh pair of eyes on it.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Michigan
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, just to show what that code went towards: http://communityhigh.org/schedule/schedule.xml

  6. #6
    SitePoint Zealot tristanm's Avatar
    Join Date
    Jan 2005
    Location
    Hampshire, UK
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a pretty damn smart piece of work. Nice one. I really need to get a good book on XML/XSLT, got any recommendations?

    Thanks.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Michigan
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I wish I was able to simplify the XSLT more, though.

    I learned XML from some huge 400-page XML bible, but I forget the title. O'Reilly has a series of books that are probably perfect. However, for this project I found the good old http://www.w3schools.com/ to be my best friend.


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
  •