By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,081 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,081 IT Pros & Developers. It's quick & easy.

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

P: 42
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     var tabela = "<table border=2 width='100%' heigth='100%'><tr>";
  3.     var lastCol = 3;
  4.  
  5.     for (var i = 1; i <= nCam; i++)
  6.     {
  7.         if (i == lastCol)
  8.         {
  9.             if(i = nCam)
  10.             {
  11.                 tabela += "</tr><tr><td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td></tr></table>";
  12.             }
  13.             else
  14.             {
  15.                 tabela += "</tr><tr><td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td>";
  16.             }
  17.             lastCol = lastCol + 3;
  18.         }
  19.         else if (i = nCam)
  20.         {
  21.             tabela += "<td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td></tr></table>";
  22.         }
  23.         else
  24.         {
  25.             tabela += "<td><img src=\"http://server.ubiwhere.com/cgi-bin/nph-zms?mode=jpeg&monitor=" + i + "\" /></td>";
  26.         }
  27.     }
  28. document.getElementById("montCam").innerHTML = tabela;
  29.  
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:

Expand|Select|Wrap|Line Numbers
  1. <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.
Jun 3 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
On line 8 and 18, you're setting i to nCam instead of comparing. Use double equals ==.
Jun 4 '08 #2

P: 42
Bingo! :D thanks for your reply acoder
Jun 4 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad it helped.
Jun 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.