Jump to content

need help for delete rows


srinivas6203

Recommended Posts

Hi

I am doing a website using php. My problem is:

 

there is textfield. If user enter into the textfield as 2 and onkeyup , 2 rows will be displayed and each one with delete button. This is working fine. But after i delete last record the field names (ex: first name, last name etc.,) are still appearing. I want to delete fieldnames after delete last record.

 

Here is my code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<script type="text/javascript" language="javascript" src="clienthint.js"></script>

<script>

function deleteRow®

{

var i=0;

var i=r.parentNode.parentNode.rowIndex;

document.getElementById('invite_conf').deleteRow(i);

}

</script>

</head>

 

<body>

<form>

<input type="text" value="<? echo $numbers; ?>" onkeyup="showHint(this.value);"><br />

<span id="txtHint"></span>

</form>

</body>

</html>

 

clienthint.js

 

// JavaScript Document

var xmlHttp

 

function showHint(str)

{

if (str.length==0)

  {

  document.getElementById("txtHint").innerHTML="";

  return;

  }

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)

  {

  alert ("Your browser does not support AJAX!");

  return;

  }

var url="username.php";

url=url+"?q="+str;

xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

}

 

function stateChanged()

{

if (xmlHttp.readyState==4)

{

document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

}

}

 

function GetXmlHttpObject()

{

var xmlHttp=null;

try

  {

  // Firefox, Opera 8.0+, Safari

  xmlHttp=new XMLHttpRequest();

  }

catch (e)

  {

  // Internet Explorer

  try

    {

    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

    }

  catch (e)

    {

    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

    }

  }

return xmlHttp;

}

 

username.php

 

<?php

$q = $_GET["q"];

if($q<2 || $q==0) {

?>

<table border="1" id="invite_conf">

<tr><td align="center">First name</td><td align="center">Last name</td><td align="center">Email</td><td align="center">Telephone</td><td align="center"><input type="button" value="Delete" onclick="deleteRow(this)" style=" border:0px; font-weight:bold; width:50px; height:20px; background:#acbdee;"></td></tr>

<?

while($i<$q)

{

?>

 

<tr><td><input type="text" name="fname[]" size=12/></td>

<td><input type="text" name="lname[]" size=12/></td>

<td><input type="text" name="email[]" size=22 onblur="vemail(this)"/></td>

<td><input type="text" name="phone[]" size=15  /></td>

<td><input type="button" value="Delete" onclick="deleteRow(this)"></td>

</tr>

<?

$i++;

}

}

?>

</table>

 

Please help me out.

Link to comment
https://forums.phpfreaks.com/topic/112576-need-help-for-delete-rows/
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.