Hello,
I am new to javascript. I am trying to get the cell values of a html table in the following way, but I am not able to increase the variable dynamically! Does any one see where is my problem
Sorry for my english!!

function validateRow(frm)
{
    var oTBL = document.getElementById('myTable');
    var lastRow = oTBL.rows.length - 1;
    var i;
    
    for (var x = 1; x < oTBL.rows.length; x++) {
    var y = 1; 
    //I am getting error here
    var (bRow+x) = (oTBL.rows[x].cells[y].firstChild.data);
    var aRow = document.getElementById('txtRow' + x);
    if (aRow.value.length <= 0) {
        alert('Row ' + x + ' is empty');
        return;
      }
    }
 
  openInNewWindow(frm);
}

function openInNewWindow(frm)
{
  // open a blank window
  var aWindow = window.open('', 'TableAddRowNewWindow',
   'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
   
  // set the target to the blank window
  frm.target = 'TableAddRowNewWindow';
  
  // submit
  frm.submit();
}

Well, there may be other errors in your code, but that line right after your comment, "I am getting error here" doesn't make sense to me.

Are you trying to declare a variable named bRow? But then you don't use it.
And that is not the proper way to define a variable.
And you cannot do an addition operation on the left side of an assignment statement (unless you are trying to access an array element by offset x, but that is still not the way to do it).

Just out of curiuosity, does the very first line in that function work?

var lastRow = oTBL.rows.length - 1;

If so, what value does lastRow have just before the program enters the for loop?

Thanks David for your reply.
1. Yes I am trying to declare bRow. Actually what I wanted to do is to declare 2 variable bRow1 abd bRow2. This is what I don't know to do. So I am trying to increase the variable in this way. You are right this is not the correct way to declare.
2. The variable lastRow, I declared it for another purpouse. But I am not using it anymore. Just to answer you, it has the value of 3.

>>"Actually what I wanted to do is to declare 2 variable bRow1 abd bRow2."

You declared other variables properly (i.e. - i, lastRow, etc.). Why don't you declare bRow1 and bRow2 the same way:

var bRow2, bRow2;

Then, make your assignments.

I would have done that if it is possible. If you read my post I am generating rows dynamically. Number of variables depands on number of rows. Do I have to increase the variable values dynamically. That is the reason why i am writing like this (bRow+x)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.