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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:14:42+00:00 2026-05-21T21:14:42+00:00

this is related to my last question ( NOTE: I already got some good

  • 0

this is related to my last question(
NOTE: I already got some good answers there). I’m doing a program that will filter. I didn’t include this question because i thought that it is easier for me to add text as long as i know how to get the data from the row. But to my dismay, I wasn’t able to code a good program til now.

Im currently using this javascript code (thanks to Awea):

$('#out').click(function(){    
   $('table tr').each(function(){
      var td = '';
      $(this).find('option:selected').each(function(){
         td = td + ' ' + $(this).text();
      });
      td = td + ' ' + $(this).find('input').val();
      alert(td);
   });
})

my question is: How to add text before the data from the row? like for example, this code alert
the first row like data1.1 data1.2 data1.3,

then the second row like data2.1 data2.2 data2.3,

I want my output to be displayed like this

[
{"name":"data1.1","comparison":"data1.2", "value":"data1.3"},
{"name":"data2.1","comparison":"data2.2", "value":"data2.3"},
{"name":"data3.1","comparison":"data3.2", "value":"data3.3"}
{.....and so on......}]

but before that happen, i want to check if all the FIRST cell in a row is not empty. if its empty, skip that row then proceed to next row.

is there somebody can help me, please…

  • 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-21T21:14:43+00:00Added an answer on May 21, 2026 at 9:14 pm

    Building on my answer to your previous question, see http://jsfiddle.net/evbUa/1/

    Once you have your data in a javascript object (dataArray in my example), you can write the JSON yourself, per my example, but you will find it much easier to use a library such as JSON-js (see this also).

    // object to hold your data
    function dataRow(value1,value2,value3) {
        this.name = value1;
        this.comparison = value2;
        this.value = value3;
    }
    
    $('#out').click(function(){   
    
        // create array to hold your data
        var dataArray = new Array();
    
        // iterate through rows of table
        for(var i = 1; i <= $("table tr").length; i++){
    
            // check if first field is used
            if($("table tr:nth-child(" + i + ") select[class='field']").val().length > 0) {
    
                // create object and push to array
                dataArray.push(    
                    new dataRow(
                        $("table tr:nth-child(" + i + ") select[class='field']").val(),
                        $("table tr:nth-child(" + i + ") select[class='comp']").val(),
                        $("table tr:nth-child(" + i + ") input").val())
                );
            }
    
        }
    
        // consider using a JSON library to do this for you
        for(var i = 0; i < dataArray.length; i++){
            var output = "";
            output = output + '{"name":"data' + (i + 1) + '.' + dataArray[i].name + '",';
            output = output + '"comparison":"data' + (i + 1) + '.' + dataArray[i].comparison + '",';
            output = output + '"value":"data' + (i + 1) + '.' + dataArray[i].value + '"}';
            alert(output);
        }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to my last question . I have an application that I
The answers to this related question of mine lead me to choose Java for
This is related to my question asked here today on SO. Is there a
This question is related to the last point of Item 46 in Effective Perl
This is related to another question I asked last week, but the current issue
This is related, but not identical to my last question . So I thought
Related to this question , how do I detect that a form user is
This question is related to my last one about jQuery 1.4. They supposedly fixed
This question is related to my last one . I am trying to solve
Possibly related to my last question (note: different error code): Why might the fatal

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.