The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jquery help

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #39323

    I am trying to hide a form before a success message on a contact page, then show the form after the success message has been displayed. the form hides fine, the success message shows but the form does not reshow after the success message has faded out. My current code

    Your message was sent.
    We will contact you shortly
    $('.sent-message').delay(4000).fadeOut("slow").('intro, form#contact_form').show();

    Try doing this:

    $('.sent-message').delay(4000).fadeOut("slow", function() {
    $('intro, form#contact_form').show();

    This is saying, “once the fadeout is completed, show our form”.


    In order for what you want to accomplish, you will need to follow what TheDoc has written.

    From what you have shown us though, it looks like you could use a quick tip on JavaScript methods.

    jQuery uses what is called method chaining. This is what allows you to do stuff like:


    The above code snippet gets the element that has the id some-id, finds each of it’s children elements with a class of some-class and fades them out.

    You can think of a method as a fancy name for a function. Methods are usually part of what is known as object oriented programming (OOP for short).

    A method inside of JavaScript might look something along the lines of:

    var myHelpers = {
    findElement: function(elm) {
    // Some code here

    // or maybe like this
    myHelpers.findElement = function(elm) {
    // Some code here

    There are many ways to accomplish methods in JavaScript.
    In the above code snipped, myHelpers is an object, and findElement is a method of myHelpers.

    So with that, you should know, fadeIn, delay, and fadeOut are all methods of the jQuery object.

    In the code you provided, you have the following:

    $('.sent-message').delay(4000).fadeOut("slow").('intro, form#contact_form').show();

    When you hit that single dot, the browser will want a method name, but none is provided, so there an error occurs. A method call Always needs a method name. So always remember that when you see code like jQuery.

    Now, what TheDoc has provided within the fadeOut method is known as a callback function. They are special in that they usually execute immediately following the successful (and sometimes unsuccessful ) execution of the initial method call; in this case fadeOut.

    I hope I have helped you in any way. If I have offended you in any way, I am truly sorry.

    If you find your self wanting to learn more JavaScript or jQuery, Code Academy is a great place to start.


Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.