Create rows/columns dynamically in ASP.net with Javascript function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rambaldi
    New Member
    • Mar 2007
    • 42

    Create rows/columns dynamically in ASP.net with Javascript function

    Although i'm working on ASP.net, i think the problem i'm facing is related to my javascript function so i hope i create the thread in the right section.

    My goal is to create a table dynamically, depending with the number of cameras i got. The code is:

    Code:
        
        var tabela = "<table border=2 width='100%' heigth='100%'><tr>";
        var lastCol = 3;
    
        for (var i = 1; i <= nCam; i++)
        {
            if (i == lastCol)
            {
                if(i = nCam)
                {
                    tabela += "</tr><tr><td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td></tr></table>";
                }
                else
                {
                    tabela += "</tr><tr><td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td>";
                }
                lastCol = lastCol + 3;
            }
            else if (i = nCam)
            {
                tabela += "<td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td></tr></table>";
            }
            else
            {
                tabela += "<td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td>";
            }
        }
    document.getElementById("montCam").innerHTML = tabela;
    tabela --> a string that will have stored the whole table;
    lastCol --> a flag i use to know when i am about to creat a third column, so i can after create another row;
    nCam --> the number of cameras i got.

    So my intention is increment on the string tabela each column and row according to the number of cameras, but what happen is that in 4 cameras, the webpage just show the last one :(

    i put the alert() function to see what the string ‘tabela’ has and it show:

    Code:
    <table border=2 width='100%' heigth='100%'><tr><td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=4/></td></tr></table>
    Why dont he increment the code that the compiler already passes through on the 'if' conditions?
    I'm not good at javascript so i thought the code sintax maybe could be wrong. Someone can help me? Warn me if i wasnt too clear.

    Thanks in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    On line 8 and 18, you're setting i to nCam instead of comparing. Use double equals ==.

    Comment

    • Rambaldi
      New Member
      • Mar 2007
      • 42

      #3
      Bingo! :D thanks for your reply acoder

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome. Glad it helped.

        Comment

        Working...