473,395 Members | 1,987 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,395 software developers and data experts.

Problem with couter stop

8
I'm having problems with the counter, the function should add a row to a table but should stop when there are 3 row added. In this case its not stopping

what is wrong in the script ?
thanks for any help


var i=0

function addRowToTable() {
if (i == 3)
{
alert("Er kunnen niet meer groepen worden toegevoegd, neem contact op met de RAB");
return;
}

var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow + i;
var row = tbl.insertRow(lastRow);

if (i == 3)
{
alert("Er kunnen niet meer groepen worden toegevoegd, neem contact op met de RAB");
return;
}
Apr 4 '07 #1
6 1201
ashsa
45
where are you incrementing the counter i ?

I'm having problems with the counter, the function should add a row to a table but should stop when there are 3 row added. In this case its not stopping

what is wrong in the script ?
thanks for any help


var i=0

function addRowToTable() {
if (i == 3)
{
alert("Er kunnen niet meer groepen worden toegevoegd, neem contact op met de RAB");
return;
}

var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow + i;
var row = tbl.insertRow(lastRow);

if (i == 3)
{
alert("Er kunnen niet meer groepen worden toegevoegd, neem contact op met de RAB");
return;
}
Apr 4 '07 #2
sonner
8
where are you incrementing the counter i ?

This is the full script, the counter adds up in the first cell of the table, I dont now if I understand oyur question so I putt the full script here

Thanks



<script>

function removeRowFromTable()
{

var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 1)tbl.deleteRow(lastRow + i)

}

var i=0

function addRowToTable() {

var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow + i;
var row = tbl.insertRow(lastRow);

if (i == )
{
alert("Er kunnen niet meer groepen worden toegevoegd, neem contact op met de RAB");
return;
}

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'checkbox';
el.name = 'txtRow';
el.id = 'txtRow' ;
el.size = 40;
}
Apr 4 '07 #3
r035198x
13,262 8TB
Thread moved to Javascript forum.
Apr 4 '07 #4
ashsa
45
Try running this code in a browser and let me know if this is what you wanted :


Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <BODY>
  3. <TABLE id='tblSample' border=1>
  4. <TR>
  5.     <Th>T1</Th>
  6.     <Th>T2</Th>
  7. </TR>
  8. </TABLE>
  9. </BODY>
  10. <script>
  11.  
  12. function removeRowFromTable() 
  13. {
  14.  
  15. var tbl = document.getElementById('tblSample');
  16. var lastRow = tbl.rows.length;
  17. if (lastRow > 1)tbl.deleteRow(lastRow + i)
  18.  
  19. }
  20.  
  21. var i=0
  22. while(i<3)
  23.     addRowToTable();
  24. function addRowToTable() {
  25.  
  26. var tbl = document.getElementById('tblSample');
  27. var lastRow = tbl.rows.length;
  28. // if there's no header row in the table, then iteration = lastRow + 1
  29. var iteration = lastRow + i;
  30. var row = tbl.insertRow(lastRow);
  31.  
  32. if (i == 3)
  33. {
  34. alert("Er kunnen niet meer groepen worden toegevoegd, neem contact op met de RAB");
  35. return;
  36. }
  37.  
  38. // left cell
  39. var cellLeft = row.insertCell(0);
  40. var textNode = document.createTextNode(iteration);
  41. cellLeft.appendChild(textNode);
  42.  
  43. // right cell
  44. var cellRight = row.insertCell(1);
  45. var el = document.createElement('input');
  46. el.type = 'checkbox';
  47. el.name = 'txtRow';
  48. el.id = 'txtRow' ;
  49. el.size = 40;
  50. cellRight.appendChild(el);
  51. i++;
  52. }
  53. </script>
  54. </HTML>
Hope that helps..
Apr 4 '07 #5
sonner
8
thanks ashsa !

I'v changed the script and it works when I add up a Row. in thos case till its 5, but when I delete a 1, 2 or more Rows, and again add a row It stops because it was already counting till 5, I post the code I'm using.
Do you have any idees?

<HTML>
<BODY>
<TABLE id='tblSample' border=1>
<TR>
<Th>T1</Th>
<Th>T2</Th>
</TR>
</TABLE>
</BODY>
<script>

function removeRowFromTable()
{

var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 1)tbl.deleteRow(lastRow - 1)

}

var i=0
while(i<1)
addRowToTable();
function addRowToTable() {

var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow + -1;
var row = tbl.insertRow(lastRow);

if (i == 5)
{
alert("stop");
return;
}

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'checkbox';
el.name = 'txtRow';
el.id = 'txtRow' ;
el.size = 40;
cellRight.appendChild(el);
i++;
}
</script>
<p>
<input type="button" value="+" onclick="addRowToTable();" />
<input type="button" value="-" onclick="removeRowFromTable();" />


</p>
<p>
<span id="spanOutput" style="border: 1px solid #000; padding: 3px;"> </span>
</p>

</HTML>
Apr 4 '07 #6
sonner
8
hello

is there anyone who has an idee about this problem ?
Apr 5 '07 #7

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

Similar topics

0
by: David | last post by:
I've written a small windows service, and I'm having a problem that I'm spending a lot more time on than I'd like. If anyone has experienced this problem and has any hints or solutions; they would...
2
by: Stampede | last post by:
Hi guys 'n' girls, I want to use callback methods when using BeginInvoke on some events. So far no problem, but know I thought about what could happen (if I'm not completly wrong). Lets say an...
1
by: Raveendra M | last post by:
Hi! I am working with ASP.NET application. In my page I am creating one Application Domain and in that domain I am calling my DLL. Using the methods of the dll. And unloading the Application...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
4
by: PiotrKolodziej | last post by:
hi I have a thread that downloades a file. Problem is : Not all files are beeing downloaded. I observed that only the small files are beeing downloaded correctly. I also cant download two files...
12
by: Justin | last post by:
I can attach my code if anyone wants to see it however I'll try to ask my question with some mark up code first. I'm having a problem terminating my process while using DoEvents. For example: ...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
15
RMWChaos
by: RMWChaos | last post by:
In my ongoing effort to produce shorter, more efficient code, I have created a "chicken and egg" / "catch-22" problem. I can think of several ways to fix this, none of them elegant. I want my code...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.