473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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:

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
3 2054
acoder
16,027 Expert Mod 8TB
On line 8 and 18, you're setting i to nCam instead of comparing. Use double equals ==.
Jun 4 '08 #2
Bingo! :D thanks for your reply acoder
Jun 4 '08 #3
acoder
16,027 Expert Mod 8TB
You're welcome. Glad it helped.
Jun 4 '08 #4

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
6
by: Brendan.Collins | last post by:
Hi I have a javascript problem that has been annoying me for two days now and thought that a javascript expert might have the magic solution. I am populating a table dynamically from the...
2
by: David Elliott | last post by:
I can create this: ?xml version="1.0" standalone="yes" ?> <ConfigOpt> <record> <Field_1>Text # 1</Field_1> <Field_2>Text # 2</Field_2> </record> </ConfigOpt>
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
4
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
2
by: somaskarthic | last post by:
Hi In my php code , i dynamically created table rows on button click event. Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the...
1
by: Tom O'Brien | last post by:
hello, This is a basic questions... i have just started using vb.... I want to figure out how to create a range dynamically. Say I have some data in a variable number of columns, in this...
1
by: graphicguru | last post by:
Hi i got some javascript from (*) these site for lock one column with js and header row with css. i am not a programmer i am a designer. i am working in a small company. i don't find such...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.