Jump to content

Add and delete row


redskin

Recommended Posts

Hallo,

someone has made this script for me, because i do not know about it.

Its work fine.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Online membership</title>
<link href="main.css" type="text/css" rel="stylesheet">
</head>

<script>
function add_formrow(){
  if (!this.table_formcontainer)
    this.table_formcontainer = document.getElementById("table_formcontainer");

  if (!this.table_formcontainer)
    return;

  var new_row = table_formcontainer.insertRow(-1);
  var new_cell1 = new_row.insertCell(0);
  var new_cell2 = new_row.insertCell(1);
  var new_cell3 = new_row.insertCell(2);

  var new_input1 = document.createElement("input");
  new_input1.type = "text";
  new_cell1.appendChild(new_input1);
  
  var new_input2 = document.createElement("input");
  new_input2.type = "text";
  new_cell2.appendChild(new_input2);

   var new_input3 = document.createElement("select");
   new_input3.name="transport[]";
   var options = ["No", "Bike", "Car", "Motorbike", "Public transport"];
   for (var i = 0; i < options.length; i++)
   {
    var option = document.createElement("option");
    option.value = options[i];
    option.text= options[i];
    try
    {
      new_input3.add(option, null);
    }
    catch(error)
    {
      new_input3.add(option);
    }
  }
  new_cell3.appendChild(new_input3);  
  }
</script>

<body>
<div id="credit"><b>T e s t</b></div>
<br>
<form method="post" action="" name="data">
<fieldset> <legend>
<font color="blue"><b>Request</b></font></legend><br>
<table id="table_formcontainer">     
 <tr>
      <td width="10">Name</td> <td>Age<td>Transport<td> </td> </td>		   
 </tr>

</table>
<table>	 
 <tr>
      	<td width="500" align="right">[ b<a href="#" onclick='add_formrow();'>+</a> ]</td>	  
 </tr>
     <tr>
            <td width="10"><br><input type="submit" name="submit" value=" S e n d "> <td> </td> <td> </td> <td> </td></td>
    </tr>
</table>
</form></fieldset>
<br>
</body>
</html> 

I just wonder how to make one more button to create kind of deleterow.

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/138026-add-and-delete-row/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.