0

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();
}
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by dan420
0

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?

Edited by DavidB: n/a

0

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.

0

>>"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.

0

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)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.