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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:14:33+00:00 2026-05-28T00:14:33+00:00

I was wondering if anyone could help me with getting this working. I’m using

  • 0

I was wondering if anyone could help me with getting this working.

I’m using HTML to create a table which has at least 1 row but no max number of rows – as they can be added/removed by the user – and 4 columns, 1st contains a checkbox and the last 2 contain drop down menus.

I wish to be able to store the values of those menus in an array only if that row’s checkbox has been checked. e.g if the first row has 1 and A as it’s dropdown values and the second row has 2 and B. If only row 1 has been checked the array should only contain [1,A]. Instead mine holds all the values including the non-checked ones i.e [1,A,2,B].

My code for Javascript function and html table are below:

function calculate(textID) {
  var table = document.getElementById('course'); //id of table
  var rowCount = table.rows.length;
  var array = []; //array to hold the values
  var c = 0;

  dmenus = document.getElementByTagName("select"); //get the drop down menus

  for (var a = 1; a < rowCount; i++) { //a = 1 as the 1st row contains column headings
    var row = table.rows[a];
    var check = row.cells[0].childNodes[0];
    if (null != check && true == check.checked) {
      for (var b = 0; b < dmenus.length; b++) {
        val = dmenus[b].options[dmenus[b].selectedIndex].value;
        array[c] = val; //set index of array to equal value of dropdown box
        c++;
      }
    } else {
      b++;
    }
  }
 
<table id="course">
  <tr>
    <td><input type="checkbox" name="ucheck" id="ucheck" onclick="checkAll('course')" /></td>
    <th style="color:white">Course Title</th>
    <th style="color:white">Credits</th>
    <th style="color:white">Grade</th>
  </tr>
  <tr>
    <td><input type="checkbox" name="tick" id="tick" /></td>
    <td><input type="text" /></td>
    <td>
      <select name="credits" id="credits">
                    <option...</select></td>
    <td>
      <select name="grade" id="grade">
                    <option...</td>
 </table>

It works only for the first row but if there are more than 1 row it doesn’t do what it’s supposed to. The coding platform I’m working on does not seem to support JQuery so Javascript code will be most appreciated.

  • 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-28T00:14:33+00:00Added an answer on May 28, 2026 at 12:14 am

    Finally got it to work, rearranged the code a little bit. There’s probably a more efficient way of doing it, but hey it works for me 😀

    var array = [];
    var narray = [];
    var a = 0;
    var b = 0;
    var c = 0;
    
    ddownselects = document.getElementsByTagName("select");
    
    //get all elements into one array
    for (var j = 0; j < ddownselects.length; j++) {
      val = ddownselects[j].options[els[j].selectedIndex].value;
      array[a] = val;
      a++;
    }
    
    var rlen = array.length / 2; //number of rows
    for (var i = 1; i <= rlen; i++) {
      var row = table.rows[i];
      var check = row.cells[0].childNodes[0];
      if (check.checked) {
        narray[b] = array[c]; //set array values to new array only if that row is checked
        b++;
        c++;
        narray[b] = array[c];
        b++;
        c++;
      } else {
        c += 2; //if not checked, got to next row's values
      }
     
    <table id="course">
      <tr>
        <td><input type="checkbox" name="ucheck" id="ucheck" onclick="checkAll('course')" /></td>
        <th style="color:white">Course Title</th>
        <th style="color:white">Credits</th>
        <th style="color:white">Grade</th>
      </tr>
      <tr>
        <td><input type="checkbox" name="tick" id="tick" /></td>
        <td><input type="text" /></td>
        <td>
          <select name="credits" id="credits">
                        <option...</select></td>
        <td>
          <select name="grade" id="grade">
                        <option...</td>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone could help me with this. I have to create
I'm getting started with RegEx and I was wondering if anyone could help me
I was just wondering if anyone could help me create a mysql function UUID_SHORT()
I was wondering if anyone could help me with this problem i'm having. I
Just wondering if anyone could help me with this. I'm new to actionscript, and
I was wondering if anyone could help me out with this. I am running
I was wondering if anyone could help me with this problem: I have to
Im wondering if anyone could help me with annotations im using in my MShart
I was wondering if anyone could help me with this minor problem. I want
I was wondering if anyone could help clear up this issue I am having.

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.