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

  • Home
  • SEARCH
  • 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 6073409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:16:04+00:00 2026-05-23T10:16:04+00:00

var input = document.getElementById(‘thumbimg’); input.addEventListener(‘change’, function() { $(input.imgcheck).attr(disabled, ); }, false); I use this

  • 0
var input = document.getElementById('thumbimg');
            input.addEventListener('change', function() {  $("input.imgcheck").attr("disabled", ""); }, false);

I use this code to enable the submit button when the user selects a file to upload.
But what If I want to add more than an upload field? I need to know how to enable the submit button only if all the upload fields are filled. Any Ideas?

  • 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-05-23T10:16:05+00:00Added an answer on May 23, 2026 at 10:16 am

    Update:

    @Simeon made an important comment and he is right. To solve this problem, you can inspect the value of each field and see whether it is empty or not:

    var $fields = $('.thumbimg'),
        $submit = $("input.imgcheck"),
         numRequiredFields = $fields.length; // or 3 as per your comment (somewhere)
    
    function runOnChange() {
        var $filledFields = $fields.filter(function(){
            return $(this).val() !== "";
        });
        if($filledFields.length >= numRequiredFields)
            // all fields changed
            // run logic here
            $submit.attr("disabled", "");
        }
        else {
            $submit.attr("disabled", "disabled");
        }
    }
    
    $fields.change(runOnChange);
    

    I hoped to avoid inspecting every field on each change, but it seems this is unavoidable.


    Original answer:

    You would have to keep track of which fields have changed. If you have more than one file upload field, you have to use classes, not IDs:

    var numFields = $('.thumbimg').length,
        changedFields = 0;
    
    function runOnChange() {
        changedFields++;
        if(changedFields >= numFields) {
            // all fields changed
            // run logic here
            $("input.imgcheck").attr("disabled", "");
        }
    }
    
    $('.thumbimg').change(runOnChange);
    

    Also, if you use jQuery anyway, then be consistent and use it throughout the script. Especially don’t use addEventListener, which does not work in IE8 and below. jQuery is there to abstract from this browser differences.

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

Sidebar

Related Questions

i have the following function function change() { var input = document.getElementById('pas'); var input2
var input = document.getElementById(myInput); a.onkeydown = function() { if (a.value.match(hi)) { a.value.replace(hi, span style='color:red;'>hi</span>);
function checkDatabase(){ var query = document.getElementById(input).value; var modQuery = query.split(@)[1]; var url = http://www.somesite.com/index.html/?id=+modQuery;
$(document).ready(function() { function countChecked() { var n = $(input:checked).length; $(div).text(n + (n <= 1
I have this function: function addButtonLookup() { var element = document.getElementById(btnToolBar); var index; for
var input; // method 1 input = document.getElementById('address').value; alert(input) // method 2 eval('input =
I'm trying to reverse an input string var oneway = document.getElementById('input_field').value(); var backway =
Im trying do this basically: var tr = document.createElement(tr); var td = document.createElement(td); td.appendChild(document.createTextNode('<input
var projectWindow; function btnNew_Click() { var form = document.createElement(form); form.setAttribute(target, projectWindow); form.setAttribute(method, post); form.setAttribute(action,
var query1 = urlencode($('input[name=searchTerm1]').val()); //user1 var query2 = urlencode($('input[name=searchTerm2]').val()); //user1 var rpp = 20;

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.