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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:11:19+00:00 2026-06-15T12:11:19+00:00

I need help on storing two columns of a html table to a Javascript

  • 0

I need help on storing two columns of a html table to a Javascript array.
I create the table dynamically using php. following is my php code;

$inc = 1;
foreach($result as $element) {
    echo "<tr><td>".$element['qs_id']."</td>";
    echo "<td>".$element['qs_desc']."</td>";
    echo "<td><input type=\"radio\" name=\"select".$inc."\" value=\"0\" ";
    if($element['qq_rate'] == '0') echo "checked=\"checked\"";
    echo "></input></td>";
    echo " <td><input type=\"radio\" name=\"select".$inc."\" value=\"1\"";
    if($element['qq_rate'] == '1') echo "checked=\"checked\"";
    echo "></input></td>";
    echo " <td><input type=\"radio\" name=\"select".$inc."\" value=\"2\"";
    if($element['qq_rate'] == '2') echo "checked=\"checked\"";
    echo "></input></td>";
    echo " <td><input type=\"radio\" name=\"select".$inc."\" value=\"3\"";
    if($element['qq_rate'] == '3') echo "checked=\"checked\"";
    echo "></input></td>";
    echo " <td><input type=\"radio\" name=\"select".$inc."\" value=\"na\"";
    if($element['qq_rate'] == '') echo "checked=\"checked\"";
    echo "></input></td>";
    echo "</tr>";
    $inc = $inc +1;
}

This populates the html table with relevant ‘id’,’desc’ etc from the database. Then it writes radio buttons with a unique tag name for each of them.
The result looks like following;
enter image description here

I want to store the id in the first column and its relevant rating (ie. 1,2,3,na) to a Javascript array.

Please help.

  • 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-15T12:11:21+00:00Added an answer on June 15, 2026 at 12:11 pm

    If you have jQuery already included or free to use it you can try the following code:

    var data = [];
    $('table tr').each(function(){
        var row = $(this);
        var id = row.find('td:first').text();
        if ($.isNumeric(id)) {
            var selectedRadio = row.find(':radio[name=select' + id + ']:checked');
            data.push([id, selectedRadio.val()]);
        }
    });
    alert(data);
    

    Demo

    If not it will be little more complex to iterate over DOM-elements but still doable )

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

Sidebar

Related Questions

Is it possible to CONCAT values of two table columns using the Yii's ActiveRecord
I've a ListView with two columns and i'm filling the ListView using the code
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
I have two columns as company and product. I use the following query to
I have two columns in excel like the following a,apple a,bannana a,orange a,plum b,apple
forum member I need one help from you all. I am having two POJO
The situation is, that i need to create table in grid view looking like
I need help grabbing some string operation in Javascript. I have a sample string
I have a simple table with two columns. The first field represents an id,
Hello I am only starting to learn php can anyone help. I need to

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.