Delete one row in html table marqued by a check box with javascript

Posted by kawtousse on Stack Overflow See other posts from Stack Overflow or by kawtousse
Published on 2010-05-04T10:05:34Z Indexed on 2010/05/04 10:08 UTC
Read the original article Hit count: 165

Filed under:

Hi everyone,

I build dynamically my HTML table from database like that:

for(i=0;i< nomCols.length;i++)
{
  retour.append(("<td bgcolor=#0066CC>")+ nomCols[i] + "</td>");

 }
retour.append("</tr>");

retour.append("<tr>");

            try {

s= HibernateUtil.currentSession(); tx=s.beginTransaction(); Query query = s.createQuery(HQL_QUERY); // inner join projecttasks.ProjectTypeCode as projects");// inner join projecttasks.taskCode as task inner join projects.projectCode as wa;");

 for(Iterator it=query.iterate();it.hasNext();)
 {                                                                           
                   if(it.hasNext()){
                       Dailytimesheet object=(Dailytimesheet)it.next();
                       retour.append("<td><input type=checkbox  name=cb id=cb  /> </td>"); 
                       retour.append("<td>" +object.getTrackingDate() + "</td>");
                       retour.append("<td>" +object.getActivity() + "</td>");
                       retour.append("<td>" +object.getProjectCode() + "</td>");
                       retour.append("<td>"  +object.getWAName() +  "</td>");
                       retour.append("<td>"  +object.getTaskCode() +"</td>");
                       retour.append("<td>" +object.getTimeSpent() + "</td>");
                       retour.append("<td>" +object.getPercentTaskComplete() + "</td>");
                                   }
                             retour.append("</tr>");


 }   

//terminer la table. retour.append (""); tx.commit();

           } catch (HibernateException e) 
            {
            retour.append ("</table><H1>ERREUR:</H1>" +e.getMessage());
            e.printStackTrace();
            }

            return retour;

} so I want that all check boxes having the same id. When trying to delete one row in my table witch have the check box checked i found a problem with that. Iam using simple javascript like this:

function DeleteARow()

{ //var Rows = document.getElementById('sheet').getElementsByTagName('tr'); //var RowsCount = Rows.length; //alert('Your table has ' + RowsCount + ' rows.'); if (document.getElementById('cb').checked==true) {

document.getElementById('cb').parentNode('td').parentNode('tr').remove();

}}

It doesn't work approperly and only the first row have the id 'cb'.

Many thanks for your help.

© Stack Overflow or respective owner

Related posts about JavaScript