java - Help deleting fields from an HTML table -


so not sure how tag one, have dynamically loaded html table, contains values can deleted, using check boxes user decide row delete. here code far:

      <table id="comments" align="center" width="59%">     <thead>       <th class="headerclass" width="7%">delete</th>       <th width="15%" class="headerclass">date</th>       <th class="headerclass" width="15%">employee</th>       <th class="headerclass">comment</th>     </thead>       <tbody>            <%   while (result.next()) {           commentdate = stringutils.defaultstring(result.getstring("commentdate"));         commentuser = stringutils.defaultstring(result.getstring("cname"));         comment = stringutils.defaultstring(result.getstring("xbs_comment"));  %>        <tr>         <td class="normal"><input type="checkbox" class="checkbox" /></td>         <td class="normal"><%=commentdate%></td>         <td class="normal"><%=commentuser%></td>         <td class="normal" width="68%"><%=comment%></td>                       </tr>    </tbody>      </table>       <label for="comment"><h4>add comment:</h4></label>    <textarea cols="105" id="comment" name="comment" rows="4"></textarea>  <br />  <div align="center" class="submit">   <input class="submit" width="10%" type="submit" name="submit" id="submit" value="submit" /> </div> 

basically have table comments, user can add comment using submit button, them able use check box delete comments. need form tag w/ delete button, or can use 1 submit button? if stay check boxes, how let end of program(function , servlet) know checked? help!!

you can along same submit. , can delete comment via ajax may reload page upon success in deletion.

here of way delete comment using same submit button. , assume user has access delete comments in table.

but them able use check box delete comments 

to must assign value on checkbox unique every comments. primary key or id in row represent each comment.

use single name every checkbox multiple delete. sample below

comments.jsp

<form name="commentform" action="adddelete.jsp">     <div> <table>     <thead>         <tr>             <th>no.</th><th>date</th><th>user</th><th>comments</th>         </tr>     </thead>     <tbody>         <%            for(comment cmnt : commentlist){         %>             <tr>                 <td><input type="checkbox" value="<%=cmnt.getcmntid()%>" name="cmntid" /></td>                 <td><%=cmnt.getcmntdate()%></td>                 <td><%=cmnt.getcmntuser()%></td>                 <td><%=cmnt.getcmntcomment()%></td>             </tr>         <%                         }         %>     </tbody> </table> <textarea cols="50" rows="10" name="newcomment"> </textarea> <br /> <input type="submit" value="delete" /> <input type="hidden" name="userid" value="id_of_the_user"> </div> </form> 

this example, focus more on part have checkbox.

adddelete.jsp

now on adddelete.jsp, have 2 queries different function. first adding new comments , second deletion of comment(s).

to list of comment delete store in array. , other fields.

string[] cmntids = request.getparametervalue("cmntid"); //this store cmntid checked in previous checkbox. string newcomment = request.getparametervalue("newcomment"); string userid = request.getparametervalue("userid"); //this can in session  //some function may need deletecomment(cmntids); //execute query delete comment using cmntids insernewcomment(newcomment, userid); //execute query add new comment using newcomment , userid if there comment attached. 

beyond part hope can handle function need want.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -