views:

144

answers:

3

I got something that I want to do and want to see what you guys think and how can it be implemented.

I got a form in a page and the form will submit to itself to perform some process (run functions) in a class.

Upon clicking the submit button, I want to animate the button text to “SUBMIT .” -> “SUBMIT ..” -> “SUBMIT …” -> “SUBMIT ….” -> “SUBMIT ….” and then back again. Sort of “animate” the button text.

Once the whole process is done, the button text will goes back to be “SUBMIT” text again.

Please note that I am not looking for image button solution, meaning that I do not want to implement gif animated button image.

Anyone done this before or know how this can be done? I have google but seems nothing of this kind to be found.

Thanks!

AL

+1  A: 

Set up a timer with javascript, that will run until the process is done, be sure to have a flag for it.

And since you are using jQuery, you can simply $("#button-id").val(nextStep); where nextStep is the next animation string. Example:

function putAnimation () {
    var b = [".", "..", "..." ];
    var i = 0;

    var a = setInterval(function () {
        $("#button-id").val("SUBMIT " + b[i++]);

        if (stopped) {
            $("#button-id").val("SUBMIT");
            clearInterval(a);
        }
    }, 500);
}
Francisco Soto
A: 

For the animation itself:

$('#submit').click(function() {
  $(this).val("Submit    ").delay(200).val("Submit .").delay(200).val("Submit ..").delay(200).val("Submit ...").delay(200).val("Submit").delay(200);
});
Tim
i can tell using `delay()` like this won't work.... :)
Reigel
Why not? It's worked for me before
Tim
A: 

Hi all,

Thanks for all your replies.

I have tried this but need some guidance whether this is the correct way to do it?

<?php

$process = new process;
if (isset($_POST['submit']) && $_POST['submit'] == "SUBMIT") {
    $process->run_now();
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test form</title>

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css.css">
<script type="text/javascript">                                         
    $(document).ready(function() {

        $('#submit').click(function() {
            putAnimation();
        });

        function putAnimation () {
            var b = [".", "..", "..." ];
            var i = 0;

            var a = setInterval(function () {
                $("#submit").val("SUBMIT " + b[i++]);

                if (stopped) {
                    $("#submit").val("SUBMIT");
                    clearInterval(a);
                }
            }, 500);
        }

    });
 </script>

</head>

<body>
<div id="main">
  <form action="" method=POST>
    <input type="submit" class="forum-button1" value="SUBMIT" id="submit" name="submit" /> 
  </form>
</div>  
</body>
</html>

Basically "run_now" is the function in the class that I would like to run after clicking submit button. This function will take some times to process and I would like the button to animate with dots while waiting for the function to finish the process. Once the process is done, the button will stop the animation.

Have I done it correctly?

Thanks.

AL