0
function AddressVal5() {
   $('.ma-addressEdit .address:visible input:text.number').each(function () {
      var maxLength = $(this).attr('maxLength');
      var thisLength = $(this).val().length;
      //  alert(maxLength + ' ' + thisLength)
      //$(this).next('.error').hide();
      if ($(this).val() == '' || thisLength < maxLength) {
         alert("sa");
         $(this).next('.error').show();
         return false;
      }
   });

   $('.ma-addressEdit .address:visible input:text, .ma-addressEdit .address:visible textarea').each(function () {
      var maxLength = $(this).attr('maxLength');
      var thisLength = $(this).val().length;
      $(this).next('.error').hide();
      if ($(this).val() == '' || thisLength < maxLength) {
         $(this).next('.error').show();
      }
   });

} 

I am working on jquery validations its work properly with

<a href="javascript:void(0);" class="clear" id="addressUpdateBtn"><img src="images/update.png" width="83" height="31" alt="Upate" onclick="AddressVal5()" /></a>                                    

but not work with

<asp:ImageButton ID="imgbtnNewADD" runat="server"
                                ImageUrl="~/_layouts/images/Experia/update.png" CssClass="Nbutton" OnClientClick="return AddressVal5();" ToolTip="Add" OnClick="imgbtnNewADD_Click" />

error messages are come but refresh on click please help..

1 Answer 1

1

Possibly that is because you have no return false; in second each statement.

EDIT: Oops. So simple! Your are doing return from each callback function and not from AddressVal5. You should have something like

function AddressVal5() {
   var isValid = true;
   $('.ma-addressEdit .address:visible input:text.number').each(function () {
      var maxLength = $(this).attr('maxLength');
      var thisLength = $(this).val().length;
      //  alert(maxLength + ' ' + thisLength)
      //$(this).next('.error').hide();
      if ($(this).val() == '' || thisLength < maxLength) {
         alert("sa");
         $(this).next('.error').show();
         isValid = false;
         return false;
      }
   });

   $('.ma-addressEdit .address:visible input:text, .ma-addressEdit .address:visible textarea').each(function () {
      var maxLength = $(this).attr('maxLength');
      var thisLength = $(this).val().length;
      $(this).next('.error').hide();
      if ($(this).val() == '' || thisLength < maxLength) {
         $(this).next('.error').show();
         isValid = false;
         return false;
      }
   });
   return isValid;
} 

to make it work. In first case it worked fine because there is no submit button.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.