views:

660

answers:

2

I was wondering if there was a function that I can add to this, that would show the data again, as in make it slide back down or something after a given set of time so you can go back and re-enter your data.

It currently just slides up after submit, and then shows the text.

 $("#help").slideUp(function() {
$("#help").before('<div class="failMessage">SOME FAIL TEXT HERE</div>');
setTimeout(ShowControlsHideFailMessage,5000);
 });

    function ShowControlsHideFailMessage()
    {
       $("#help").slideDown();
       $('.failMessage').addClass('hidden');
    }
+2  A: 

The code sample below will use the setTimeout function to call $("#help").slideDown() after 5 seconds. Also, If you want to hide the "FAIL TEXT", I'd suggest using a CSS class for that message like this:

$("#help").slideUp(function() {
   $("#help").before('<div class="failMessage">SOME FAIL TEXT HERE</div>');
   setTimeout(ShowControlsHideFailMessage, 5000);
});

function ShowControlsHideFailMessage()
{
   $("#help").slideDown();
   $('.failMessage').addClass('hidden');
}

You can use the class failMessage for red fonts or anything special to that message and then create a hidden class that sets the display to none.

RSolberg
For some reason this doesn't timeout haha. It does a slideUp, and then immediately slides back down, but after it slides back down, the text is still above it.
Homework
Remove the parenthesis from the setTimeout function as updated above... should read setTimeout(ShowControlsHideFailMessage, 5000);
RSolberg
I updated the question with the full code that I am using if that helps, I think I am doing so much wrong!
Homework
@Joey: It was a parenthesis error in my answer. I've corrected... You should be good to go now.
RSolberg
I've used your updated code, it still doesn't timeout? Hmm...
Homework
Actually it works, thanks! Also could you tell me why it's showing $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(100);Again? Do I just have to put a div class on that as well?
Homework
Actually, I think a fadeout might work.
Homework
@Joey: Not sure... if you were to post your HTML snippets in addition to your current js, I could take a peak.
RSolberg
Posted, towards the bottom. That's ALL of it, as the rest is php, etc. I'm going to try a fadeout, it seems as if it would work.
Homework
+1  A: 

Here's a better way:

var failMessage = $('<div class="failMessage" />');
failMessage.text('SOME FAIL TEXT HERE');
//Create the failMessage beforehand

$("#help")
    .slideUp(function() {
        $(this).before(failMessage);
    })
    .delay(5000)
    .slideDown(function () {
        failMessage.hide();
    }​);​
Eric