File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to delete the rows which are checked Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to delete the rows which are checked" Watch "how to delete the rows which are checked" New topic
Author

how to delete the rows which are checked

sowmya vasisht
Ranch Hand

Joined: Aug 23, 2001
Posts: 35
<HTML>
<SCRIPT LANGUAGE="JScript">
var str="";
var str1="";
var str2="";
var str3="";
var stock = new Array;
var oRow;
var box;
function addvalue(f)
{
var oCell;
var i, j;
var check="";
stock["0,0"] = f.Employees.options[f.Employees.options.selectedIndex].text;
alert(f.Employees.options.selectedIndex)
stock["0,1"] = f.Tests.options[f.Tests.options.selectedIndex].text;
stock["0,2"] = f.Time.value;
stock["0,3"] = f.Date.value;
// Insert rows and cells into the first body.
for(i=0; i<1;i++)
{
oTBody0.scrollTop=true;

alert("ALERTING CHECK ")
oRow = oTBody0.insertRow();
alert("oRow.sectionRowIndex"+oRow.rowIndex)
oCell = oRow.insertCell();
box = "<INPUT type=checkbox name=checkbox id=chkBX value=check >";
oCell.innerHTML = box

alert("oCell.chekboxvalue"+oCell.innerHTML.value)
for (j=0; j<4; j++)
{
oCell = oRow.insertCell();
oCell.innerHTML = stock[i + "," + j];
alert(stock[i + "," + j])
}
alert(eval("document.Form1.checkbox.checked"));
str+=stock["0,0"]+","
alert("displayng str "+str)
document.forms[0].ResultEmpNames.value = str;
alert("prntng the result value "+document.forms[0].ResultEmpNames.value)
str1+=stock["0,1"]+","
alert("displayng str1 of tests "+str1)
document.forms[0].ResultAssTests.value = str1;
alert("prntng the result value "+document.forms[0].ResultAssTests.value)
str2+=stock["0,2"]+","
alert("dsplayng dates "+str2)
document.forms[0].ResultDates.value = str2;
alert("prntng the result value "+document.forms[0].ResultDates.value)
str3+=stock["0,3"]+","
alert("dsplayng dates "+str3)
document.forms[0].ResultTime.value = str3;
alert("prntng the result value "+document.forms[0].ResultTime.value)
alert(oRow.innerText+"oRow.innerText")
}
}
function removevalue()
{
if(oTable.rows.length>0)
{
for(var i=7; i<(oTable.rows.length+7); i++)
{
alert(document.forms[0].elements[i].value+" ALERTING")

if(document.forms[0].elements[i].checked==true)
{
alert(oTable.rows.length)
//oRow.sectionRowIndex=i;
alert(box.value+"oooooooooooooooooo")
oTable.deleteRow(oTable.rows[i])

}
}

}

}
/*alert(eval("document.Form1.checkbox.checked"));
alert(box.value)
alert(document.forms[0].ResultEmpNames.value)
//oTBody0.deleteRow(oRow.rowIndex);
oTBody0.deleteRow();*/
function getListItems(theform)
{

alert(oRow.length)
alert(oRow.innerText+"--------------oRow.innerText")

//document.forms[0].ResultEmpNames.value = oRow.innerText;
//alert(document.forms[0].ResultEmpNames.value)
/*str+=stock["0,0"]+","
alert("displayng str "+str)
document.forms[0].ResultEmpNames.value = str;
alert("prntng the result value "+document.forms[0].ResultEmpNames.value)
str1+=stock["0,1"]+","
alert("displayng str1 of tests "+str1)
document.forms[0].ResultAssTests.value = str1;
alert("prntng the result value "+document.forms[0].ResultAssTests.value)
str2+=stock["0,2"]+","
alert("dsplayng dates "+str2)
document.forms[0].ResultDates.value = str2;
alert("prntng the result value "+document.forms[0].ResultDates.value)
str3+=stock["0,3"]+","
alert("dsplayng dates "+str3)
document.forms[0].ResultTime.value = str3;
alert("prntng the result value "+document.forms[0].ResultTime.value)
alert("prntng the result value "+document.forms[0].ResultEmpNames.value)*/

}

function selectAll(chk)
{
for (var i=0;i < document.forms[0].elements.length;i++)
{
var e = document.forms[0].elements[i];
if (e.type == "checkbox")
{
e.checked = chk.checked
}
}
}

function createRadioButton(){
// Create radio button object with value="First Choice" and then insert
// this element into the document hierarchy.
var newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='First Choice'>")
document.body.insertBefore(newRadioButton);
// Create radio button object with value="Second Choice" and then insert
// this element into the document hierarchy.
newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='Second Choice'>")
document.body.insertBefore(newRadioButton);
}

</SCRIPT>
<body bgcolor="#FFFFFF" text="#000000">
<form name=Form1 id=Form1 action="/nextcard/TMSConfirmTest" method=POST>
<table width="89%" border="1" height="100">
<tr align="left" valign="top">
<td colspan="2" height="62" bgcolor="#EFDFCE" valign="baseline">
<img src="/nextcard/Images/Testlogo.gif" width="152" height="80">
<img src="/nextcard/Images/index_r03_c04slk.gif" width="104" height="17">
<font face="Arial, Helvetica, sans-serif" color="#660099" size="+2">
Assign Online Test</font> 
<img src="/nextcard/Images/index_r03_c04slk.gif" width="216" height="19">
<img src="/nextcard/Images/index_r01_c01slk.gif" width="102" height="73">
</td>
</tr>
</table>
<table width="89%" border="1" height="192">
<tr bgcolor="#DDE0E6">
<td width="48%" height="63" align="left" valign="top" bgcolor="#999999"> <p>
     

<b>Employees:</b>
<select name="Employees" style="width:136;">

<OPTION >som</OPTION>
<option >yat</option>
<option >ram</option>

</P>
</select>
<b>Tests Available:</b>
<select name="Tests" style="width:136;">

<option >java</option>
<option >oops</option>
<option >c++</option>

</select>
<STRONG>        
Time:
<input name="Time" size="10" >     
Date:</STRONG>
<input name="Date" size="15" >
</P>
              
              
              
              
    
<INPUT name=add onclick=addvalue(this.form) type=button value=add>
              
          
           
       
<INPUT name=remove onclick=removevalue(this) type=button value=remove>
<table width="70%" border="0" cellspacing="1" cellpadding="1" height="28" bordercolor="#9999ff">
<tr bgcolor="#ccccff" align="middle" valign="center">
<td width="25%" height="2"><b> Check All</b>
<input type="checkbox" name="checkbox" value="checkbox" onclick=selectAll(this)>
</td>
<td width="25%" height="2"><b> Employee Names</b></td>
<td width="20%" height="2"><b>Online Tests</b></td>
<td width="25%" height="2"><b> Date</b></td>
<td width="20%" height="2"><b>Time</b></td>
</tr>

<TABLE ID="oTable" BORDER =1 BGCOLOR="c6a893">
<TBODY ID="oTBody0"></TBODY></TR></TABLE> 
<input type=IMAGE src="/nextcard/images/Notify.gif" width="150" height="20" name="OK" onClick=getListItems(this.form) action="/nextcard/TMSConfirmTest" method=post>
<INPUT name=ResultEmpNames type=hidden >
<INPUT name=ResultAssTests type=hidden>
<INPUT name=ResultDates type=hidden>
<INPUT name=ResultTime type=hidden>
</table>
</form>
</BODY>
</HTML>
Mohamed Yousuff
Ranch Hand

Joined: Jun 23, 2001
Posts: 73

I have tried the html you have given and found that there is no checkbox except for one. Assuming that you will have rows of checkboxes for each record, I would like to suggest a solution. I assume that the rows which contain the checkboxes represent a record from the database. I also assume that there is a field in the table which identifies the record.
You can assign the name of the checkboxes as "chk_" and the unique field value. Let me give you a practical example. A table which has the employee information.
Table Name : Employee
Fields :
emp_code Autonumber
emp_name varchar
emp_age int
The sample values in this table may be as follows
Emp_code emp_name emp_age
45 emp1 25
67 emp5 23
78 emp8 18
In this scenario, you may show these details as individual rows on the html page with each row having a checkbox for deleting that record.
Now, the name of the checkbox is what really matters. You must assign the name of the checkbox with some naming convention. For instance, for the above records, the name of the checkboxes may be
chk_45
chk_67
chk_78

Note that the names of the checkboxes have a constant prefix as "chk_" and the suffix is the unique number that identifies the record.

Now in the code where you will process this page ( ASP, Servlet etc ) you have to scan all the parameter names that is received. If you are using java servlets, use request.getparameters() method. If you are using ASP, you can use Request.querystring.allkeys property or request.form.allkeys property depending on the situation.
Use the substring or any other methods on a string to check if any of the parameter name starts with "chk_". If that is the case, use the characters after "chk_" to identify the records that the user has selected for deletion.

Hope this information is useful and has detailed explanation for you to proceed. All the best.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to delete the rows which are checked