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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:19:24+00:00 2026-05-16T07:19:24+00:00

I have two JavaScript code snippets. These perform specific task when an ‘Update’ button

  • 0

I have two JavaScript code snippets. These perform specific task when an ‘Update’ button is clicked.

I would like to merge them. Any help is appreciated.

JavaScript 1: When the button is clicked, it checks if at least one checkbox is selected:

function doUpdate(){
    var c = document.getElementsByTagName('input'); 
    for (var i = 0; i < c.length; i++) { 
        if (c[i].type == 'checkbox' && c[i].checked == true) { 
            // At least one checkbox is checked     
            document.holiDay.command.value= 'update';
            document.holiDay.submit();  
            return true; 
        } 
    } 
    // Nothing has been checked 
    alert("Please identify what warehouses comply:"); 
    return false; 
}

JavaScript 2: When any checkbox is checked and update button is clicked, check all of them or uncheck all of them if any checkbox is unchecked; then perform the update feature:

function doUpdate(){
    checked=false;
    function All (holiDay) {
        var all= document.getElementById('holiDay');
        if (checked == false){
            checked = true
        }
        else{
            checked = false
        }
        for (var i =0; i < all.elements.length; i++){ 
            all.elements[i].checked = checked;
        }
    }
    //after checked or unchecked all checkboxes then submit the form and other functionality
    document.holiDay.command.value= 'update';
    document.holiDay.submit();  
    return true; 
} 
  • 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-16T07:19:25+00:00Added an answer on May 16, 2026 at 7:19 am

    I’m really not sure what you want to do, but here’s a stab at it:

    function doUpdate(){
        var c = document.getElementsByTagName('input');
        for (var i = 0; i < c.length; i++) {
            if (c[i].type == 'checkbox' && c[i].checked == true) {
                // At least one checkbox is checked    
                UpdateHoliday();
                return true;
            }
        }
        // Nothing has been checked
        alert("Please identify what warehouses comply:");
        return false;
    }
    
    function UpdateHoliday(){
        checked = false;
        function All (holiDay) {
            var all = document.getElementById('holiDay');
            checked = !checked;
            for (var i =0; i < all.elements.length; i++){
                all.elements[i].checked = checked;
            }
        }
        //after checked or unchecked all checkboxes then submit the form and other functionality
        document.holiDay.command.value = 'update';
        document.holiDay.submit();  
    } 
    

    It would really help to simplify and indent your code so that we could understand it more clearly.

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

Sidebar

Related Questions

I have two simple textareas where in i want to highlight the javascript code
I have two <div> elements, and the following JavaScript code: var myObject = {
I have two types of JavaScript files. One contains static code and the other
I have two session variables that I retrieve in a Javascript code. This is
I have two javascript objects: var a = { x: 1, y: { faz:
I have two JavaScript arrays: var array1 = [Vijendra,Singh]; var array2 = [Singh, Shakya];
So, I have two JavaScript functions: function Generate() { //Do something $.ajax({data:{Svc: 'cpMain', Cmd:
I have a two JavaScript files: Main.js Pmt.js I'm also using thick box (Ajax
I have created two JavaScript files. One file is "validators.js" and the other is
I have two arrays in JavaScript: var xcoord = []; and var ycoord =

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.