Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS function help 1

Status
Not open for further replies.

JohnShell

Technical User
Aug 29, 2003
35
0
0
US
Have the following two functions - first one adds max of 3 rows to a table - one row added each time user clicks button:

Code:
<script type="text/javascript">
var showing = 0;

function showAnother() 
{
    if ( showing <= 3 ) 
    {
       ++showing;
       document.getElementById("row"+showing).style.display ="";
	    	}
	if ( showing > 3)
		{
		alert("You have added the maximum number of rows available.");
	}
}
</script>

The next function allows a user to remove the last added row:

Code:
<script type="text/javascript">
function removeRow() 
{
    if ( showing >= 0 ) 
    {
       showing--;
       document.getElementById("row"+showing).style.display ="none";
	    	}
	if ( showing = 0 )
		{
	alert("You have removed all of the added rows.");
	}
}
</script>

How can I change the removeRow() function so that a user can remove each added row - one at a time?

Thanks, John
 
Use an else instead of your second if statement in each function. As well in your removeRow function, you use
Code:
if ( showing = 0 )
which should be
Code:
if ( showing =[b][red]=[/red][/b] 0 )

Lee
 
trollacious,

Thank you very much. I shall apply your recommendation tomorrow at work, first thing.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top