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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:51:29+00:00 2026-05-25T18:51:29+00:00

What is want is – when the checkbox is checked option no. 5 in

  • 0

What is want is – when the checkbox is checked option no. 5 in select list will be selected and when the checkbox is unchecked option no. 0 will be selected in the select list.

The select list and the checkboxes are generated dynamically in the php code as below :

echo "<select name='coupons".$i."' id='coupons".$i."'>";
------- All Options --------
echo "</select>";


<input type='checkbox' name='myCheckbox[]' value='<?php echo $i."_".$row->id; ?>' onclick='setCCode("myCheckbox[]",<?php echo $i;?>)'> 

 -----------------------------------------------------------------------------

Solved the second requirement on my own now ….. thanks to all for your inputs

just added the following line in the checkAll() within the for loop

setCCode(children[i],i+1);

The javascript function :

function setCCode(checkbox_name,i) 
{   
    var form_object = document.getElementsByName(checkbox_name+"["+i+"]");
    var selname = document.getElementsByName("coupons"+i)[0];

    if(form_object.checked) {
            selname.selectedIndex = 5;
    }
    else {
        selname.selectedIndex = 0;
    } 
}

The above issue is solved……. thanks to all

Now what i need to do is when a user checks a checkbox to select or deselect all the dynamically generated checkboxes on the form the above logic should work.

<input type='checkbox' name='checkall' onChange="checkAll(this, 'myCheckbox[]')">
<span class="chkall">Check / Uncheck All</span>

<input type='checkbox' name='myCheckbox[]' value='<?php echo $i."_".$row->id; ?>' onclick='setCCode(this,<?php echo $i;?>)'>

The javascript code i am using to select/deselect all checkboxes on form is as below :

function checkAll(parent, field)
{
    var children = document.getElementsByName(field);
    var newValue = parent.checked;

    for (i = 0; i < children.length; i++){
    if (children[i].disabled == false) {    
        children[i].checked = newValue;
    }
    }
}

function setCCode(Sender,i) 
{   
  document.getElementsByName("coupons"+i)[0].selectedIndex = Sender.checked ? 5 : 0;
}
  • 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-25T18:51:30+00:00Added an answer on May 25, 2026 at 6:51 pm

    You can pass refference to the checkbox itself as a parameter

    <input type='checkbox' name='myCheckbox[]' value='<?php echo $i."_".$row->id; ?>' onclick='setCCode(this,<?php echo $i;?>)'>
    
    function setCCode(Sender,i) 
    {   
      document.getElementsByName("coupons"+i)[0].selectedIndex = Sender.checked ? 5 : 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want to populate dynamically combobox-listbox-drop-down using javascript. var table = document.createElement(table); var select =
Want to mimic php code in c# . I want to Capture raw image
want to access select list where id starts with sentidd $('.select[id^=sentidd]').change(function() {} It fails.
Want to code a key pad for an calculator. What I want to make
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Want to work with 4-5 devs over internet on PHP projects. Question : Is
want to query below xml <courseList filedUnder=Courses> <category code=4wd title=4wd Operation> <product code=lr title=4wd
Want i want to do is i get a number from a php script.
Want to make a vocabulary list in HTML & CSS that looks like this:
Want to forward the following: localhost/bla/index.html -> localhost/index.php?s=bla/index.html localhost/blub.html -> localhost/index.php?s=blub.html localhost/blog.html?site=10 -> localhost/index.php?s=blog.html&site=10

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.