Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
What i want to do is to shake the textbox if the textbox is empty. But i a unable to do this.
What i am doing is as follows :

C#
$("#BtnSubmit").click(function() {
              if ($("#txt1").val() == '' || $("#TextBox1").val() == '' || $("#TextBox2").val()) {
                  $("#txt1").effect("shake")

              }

          });

XML
<div id="keepTextBox">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <asp:TextBox ID="txt1" ForeColor="White" runat="server" Height="30px" Style="background-color: #46375E;"></asp:TextBox>&nbsp;&nbsp;
              <asp:RequiredFieldValidator ControlToValidate="txt1" ID="rftxt1" runat="server" SetFocusOnError="true"></asp:RequiredFieldValidator>
              <asp:TextBox ID="TextBox1" ForeColor="White" runat="server" Height="30px" Style="background-color: #46375E"></asp:TextBox>&nbsp;&nbsp;
              <asp:RequiredFieldValidator ControlToValidate="TextBox1" ID="rfTextBox1" runat="server"
                  SetFocusOnError="true"></asp:RequiredFieldValidator>
              <asp:TextBox ID="TextBox2" runat="server" ForeColor="White" Height="30px" Style="background-color: #46375E"></asp:TextBox>&nbsp;&nbsp;
              <asp:RequiredFieldValidator ControlToValidate="TextBox2" ID="rfTextBox2" runat="server"
                  SetFocusOnError="true"></asp:RequiredFieldValidator>
              <asp:Button ID="BtnSubmit" runat="server" Width="15%" Text="SIGN UP" ForeColor="White"
                  Style="background-color: #49A7E4; cursor: pointer;" Height="40px" /></div>
      </div>


I want that if any textbox is empty the the textbox should shake. Thank you.
Posted
Comments
Shemeemsha (ഷെമീംഷ) 19-Sep-14 3:39am    
I think you can use jquery animate inside the validation function..
change the width slightly and add a small angle rotation .After this revert it to its old state..make it fast..I think it will work...
Sergey Alexandrovich Kryukov 19-Sep-14 4:19am    
Using all those non-breakable blank spaces repeated many times is a really dirty way of making layouts...

Now, did you check that all IDs match? Did you check it up under the debugger, that all selectors return actual element wrappers, and every other steps go correctly?

—SA
Rambo_Raja 19-Sep-14 5:02am    
thank you shemeemsha,Sergey for vauluable comments . I will try to work as suggested by you. Thanks.
Shemeemsha (ഷെമീംഷ) 19-Sep-14 7:24am    
Welcome :)

1 solution

I suspect what is happening is that your ID's are getting mangled when the page is server side rendered by ASP.

you are most likely going to have to change your javascript to look something like...

'<%= txt1.ClientID %>'
JavaScript
$("#<%= BtnSubmit.ClientID %>").click(function() {
    if ($("#<%= txt1.ClientID %>").val() == '' || $("#<%= TextBox1.ClientID %>").val() == '' || $("#<%= TextBox2.ClientID %>").val()) {
        $("#<%= txt1.ClientID %>").effect("shake")
    }
});


for an example of shake the following should help:

http://api.jqueryui.com/shake-effect/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900