Prodeep Chatterjee
Prodeep Chatterjee

Reputation: 265

Shake effect on text syntax in JQuery

I am trying to give shake effect on my input type text when validation fails. It is giving shake effect but I don't know how to change default value of direction, distance and times. Also I think I'm doing something wrong in storing value of textbox in variable a. Please tell me the correct syntax. Thank you.

<!DOCTYPE html>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script>
            $(document).ready(function(){
                $("#submitBtn").click(function(){
                    $a = $("#userNameTxt").value;
                    if ($a != "text")
                    {
                        $("#userNameTxt").effect("shake");
                    }
                });
            });

        </script>

    </head>
    <body>
        <form action="#" >
        <input type="text" name="userNameTxt" id="userNameTxt" placeholder="username" />
        <br/>
        <input type="submit" value="submit" id="submitBtn" />
        </form>

    </body>
</html>

Upvotes: 3

Views: 1951

Answers (2)

Parthik Gosar
Parthik Gosar

Reputation: 11646

This should do it.

$("#userNameTxt").effect('shake', { 
times: 10,
duration: 1000,
direction: 'left' // 'right' for right
});

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 122006

Some thing like these options ??

 $("#button").click(function(){
         $(".target").effect( "shake", 
          {times:4}, 1000 );
      });

Here is shake effect fully explained

Upvotes: 3

Related Questions