Jump to content

JQuery - .attr();

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Root23

Root23

    Programmer

  • Members
  • PipPipPipPip
  • 144 posts
I had this working 20 minutes ago. Somewhere along the lines of fixing a few other issues, I removed something I shouldn't have. Now.. for the life of my I can't get it working again.

I've got this JQuery:
            var calBtn = $('#calButton').attr('value');
            function disappearingTable() {
                if (calBtn = 'Turn Calendar Off') 
                {
                    $('.calendarLayer').toggle();
                    $('#calButton').attr('value', 'Turn Calendar On');
                }
                else if (calBtn = 'Turn Calendar On') 
                {
                    $('.calendarLayer').toggle();
                    $('#calButton').attr('value', 'Turn Calendar Off');
                }
            }

And this in the HTML
                <form id="calendarForm" action="javascript:void(0);">
                    <input type="submit" id="calButton" value="Turn Calendar Off" onclick="disappearingTable()" />
                </form>

Here's what happens:

Page loads and displays a calendar. There is a button above the calendar (see above code) that says "Turn Calendar Off". I click on the button & the calendar disappears and the text changes to "Turn Calendar On". I click the button again & the calendar reappears, but my text is not changing back.

No errors are popping up in the FireBug console. I'm new to JQuery and Javascript.. so sorry if the problem is easily found.

Everything looks correct to me.. I'm banging my head here.

Any help would be appreciated.

Thanks
Posted Image

#2
Root23

Root23

    Programmer

  • Members
  • PipPipPipPip
  • 144 posts
Oh boy... hours of editing and I miss something I should have caught.

I had my variable outside of the function, and I didn't think it would matter because I thought that meant it was global & would work anyways.


Problem fixed.. along with fixing my equalities I fudge in the process.

Stackoverflow saved the day on that one.. even though I posted on there after 12.. so it's still late. But at least I can turn it in now, and not have a headache for another 2 hours.

Edited by Root23, 22 April 2011 - 09:25 PM.

Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users