Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:44:52+00:00 2026-06-02T03:44:52+00:00

Instead of pasting $(‘html, body’).animate({ scrollTop: 0}, 2500); for every input, can I write

  • 0

Instead of pasting $(‘html, body’).animate({ scrollTop: 0}, 2500); for every input, can I write it only once to work for all inputs?

Whats happening is my screen is scrolling to the top several for every event in the script and I can’t scroll down anymore.

Thanks.

$(function () {
$('#rbSubmit').formValidator({
    scope: '#form_register',
    onError: function () {
        if ($('#input_2     input').hasClass('error-input')) {
            $('#r2 div, #r2 input').css('background-color', '#C1272D').css('color', '#FFF');
            $("#error-div").show();
            $('html, body').animate({
                scrollTop: 0
            }, 2500);
        } else {
            $('#r2 div').css('background-color', '#2F2F2F');
            $("#error-div").hide();
        }
        if ($('#input_3     input').hasClass('error-input')) {
            $('#r3 div, #r3 input').css('background-color', '#C1272D').css('color', '#FFF');
            $("#error-div").show();
            $('html, body').animate({
                scrollTop: 0
            }, 2500);
        } else {
            $('#r3 div').css('background-color', '#2F2F2F');
            $("#error-div").hide();
        }
        if ($('#input_7     input').hasClass('error-input')) {
            $('#r7  div,#r7 input').css('background-color', '#C1272D').css('color', '#FFF');
            $("#error-div").show();
            $('html, body').animate({
                scrollTop: 0
            }, 2500);
        } else {
            $('#r7 div').css('background-color', '#2F2F2F');
            $("#error-div").hide();
        }
        if ($('#input_10 textarea').hasClass('error-input')) {
            $('#r10 div').css('background-color', '#C1272D').css('color', '#FFF');
            $("#error-div").show();
            $('html, body').animate({
                scrollTop: 0
            }, 2500);
        } else {
            $('#r10 div').css('background-color', '#2F2F2F');
            $("#error-div").hide();
        }
    }
});
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:44:54+00:00Added an answer on June 2, 2026 at 3:44 am

    Theres no way for me to test this as I don’t have your markup or anything.. but I think you could really reduce the code your using by doing something like the following.

    $(function () {
        $('#rbSubmit').formValidator({
            scope: '#form_register',
            onError: function () {
                var isError = false;
                $('#form_register input').each(function(){
                    var inputNum = $(this).id.split('_')[1];
    
                    if($(this).hasClass('error-input')){
                         isError = true;
    
                         $('#r' + inputNum +' div, #r' + inputNum +' input').css('background-color', '#C1272D').css('color', '#FFF');
                         $("#error-div").show();
                    }else{
                         $('#r'+ inputNum + ' div').css('background-color', '#2F2F2F');
                    }
                });
    
                if(isError){
                    $('html, body').animate({
                        scrollTop: 0
                    }, 2500);
                } else {
                   $("#error-div").hide();
                }
            }
        });
    });
    

    ​Basically it checks all the inputs and checks if they have the error class, if so grabs the number (since you are referencing numbers in your id’s not a good practice by the way). It then selects the related elements and does what it needs to do although I think this could be improved by selecting them based upon their position related to the errored input in the document. After all of that, if there was an error in any of them it sets a flag, and performs the animation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 10 drop down list controls that get populated. Instead of copying/pasting
It seems that WMD-Editor is posting HTML to the server instead of the markdown.
Instead of individually calling $(#item).removeClass() for every single class an element might have, is
instead of popup from center can we change to another animation (eg, undo animation)?
E.g. I got a cell with the formula LEN(A3). Pasting it to an HTML
I am designing a creation wizard in ASP.NET MVC 1 and instead of posting
Instead of using an interface like this: public interface IStartable { void Start(); void
Instead it just opens the new frame, and when that one closes.. it not
Instead of just using urllib does anyone know of the most efficient package for
Instead of having an add() method in the repository, I would like to overload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.