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 8044141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:07:58+00:00 2026-06-05T05:07:58+00:00

I have an issue in image validation using jQuery Or JavaScript. Please see code

  • 0

I have an issue in image validation using jQuery Or JavaScript.

Please see code below when I tried myself.

Briefing

I want to validate multiple images with the help of for loop.

Issue (Validate Ordering)

When I press submit button this code has validate images in DESC order (see image below) and I want ASC order like 1 field is required... and then 2 field is required etc

Code:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function imageValidation(){
    return_var = 'true';

    for(var i=1; i<4; i++){
        if(($('#player-'+i).val()) == ''){
            return_var = i+' field is required';
        }
    }
    alert(return_var);
    return false;

}   
</script>

<form onsubmit="return imageValidation()">
1 <input type="file" id="player-1" name="players[]" /><br />
2 <input type="file" id="player-2" name="players[]" /><br />
3 <input type="file" id="player-3" name="players[]" /><br />
<input type="submit" />
</form>

image

enter image description here

  • 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-05T05:07:59+00:00Added an answer on June 5, 2026 at 5:07 am

    i have added a new line of code, just break; when first condition match. it will resolve your problem

    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
    function imageValidation(){
        return_var = 'true';
    
        for(var i=1; i<4; i++){
            if(($('#player-'+i).val()) == ''){
                return_var = i+' field is required';
                break;// break immediately rather wait to complete the loop.
            }
        }
        alert(return_var);
        return false;
    
    }   
    </script>
    
    <form onsubmit="return imageValidation()">
    1 <input type="file" id="player-1" name="players[]" /><br />
    2 <input type="file" id="player-2" name="players[]" /><br />
    3 <input type="file" id="player-3" name="players[]" /><br />
    <input type="submit" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some strange issue using jQuery Validation plugin. Firs of all here is
Please i have an issue with my form background image display. It works well
I have am using the jQuery validation plugin (1.8.1 from MS CDN) to validate
I have an issue where an image resource (Default.png) is included in a build
So here's my issue. I have an image that I need to shrink. The
Share your ideas please! I have issue to check the folder and convert a
Possible Duplicate: Css z-index problem I have an issue where one image is infront
Hii I have an issue in drag and touch an image. I have 3
I have an issue with my code, I have two blocks of code of
I have an issue with causes validation on my link button in my aspx

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.