469,343 Members | 5,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

problem in deleting multiple browse buttons

149 100+
hi,
i had developed jsp page..in it im facing problem with delete the multiple buttons..can any one help me out.here is the code
Expand|Select|Wrap|Line Numbers
  1. <%@ taglib prefix="s" uri="/struts-tags" %>
  2. <html>
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.         <title>JSP Page</title>
  6.         <SCRIPT language="javascript">
  7. function deleteRow(tableID) {
  8.             try {
  9.             var table = document.getElementById(tableID);
  10.             var rowCount = table.rows.length;
  11.  
  12.             for(var i=0; i<rowCount; i++) {
  13.                 var row = table.rows[i];
  14.                 var chkbox = row.cells[0].childNodes[0];
  15.                 if(null != chkbox && true == chkbox) {
  16.                     table.deleteRow(i);
  17.                     rowCount--;
  18.                     i--;
  19.                 }
  20.  
  21.             }
  22.             }catch(e) {
  23.                 alert(e);
  24.             }
  25.         }
  26.  
  27.     </SCRIPT>
  28.     </head>
  29.     <body>
  30.         <TABLE id="dataTable" width="350px" border="1">
  31.         <TR>
  32.             <s:file name="AppContent" id="UploadAppFile" label="Application File " />
  33.         </TR>
  34.     </TABLE>
  35.  
  36.  
  37.         <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
  38.         <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
  39.     </body>
  40. </html>
  41.  
can any one help me out...its urgent.
Sep 16 '10 #1
23 1663
RamananKalirajan
607 512MB
Can you describe what are the problems you face

Thanks and Regards
Ramanan Kalirajan
Sep 16 '10 #2
madhuriks
149 100+
hi RamananKalirajan,
thanks for ur reply..if i click delete button im getting error as 'TypeError:row.cells[0] is undefined' can u help me how to get deleted by clicking delete button in form
Sep 16 '10 #3
RamananKalirajan
607 512MB
Hi Madhuriks,
I have seen your code. The code row.cells[0] means for very row you are trying to fetch the first td in that tr. But in your HTML Code
Expand|Select|Wrap|Line Numbers
  1. <TABLE id="dataTable" width="350px" border="1">
  2.          <TR>
  3.              <s:file name="AppContent" id="UploadAppFile" label="Application File " />
  4.          </TR>
  5.      </TABLE>
You are directly updating the data in TR. Just check whether there is td in that table. Once you generate that JSP just right click and see the view source. Just checj whether TD is generated for that.

Thanks and Regards
Ramanan Kalirajan
Sep 16 '10 #4
madhuriks
149 100+
hi gud mrng,
i had done the changes..if i click delete everytime it is deleted one by one...but i need the default i.e., when you run the page the 1st browse button 'File: Browse' it should not get deleted...here is the code
Expand|Select|Wrap|Line Numbers
  1.   <%@ taglib prefix="s" uri="/struts-tags" %>
  2. <html>
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.         <title>JSP Page</title>
  6.         <script language="javascript">
  7.             function addRow(tid) {
  8.                 var table = document.getElementById(tid);
  9.                 var rowCount = table.rows.length;
  10.                 var row = table.insertRow(rowCount);
  11.                 var cell1 = row.insertCell(0);
  12.                 var element1 = document.createElement("input");
  13.                 element1.type = "file";
  14.                 cell1.appendChild(element1);
  15.             }
  16.             function deleteRow(tid) {
  17.                 try {
  18.                     var table = document.getElementById(tid);
  19.                     var rowCount = table.rows.length;
  20.                     //for(var i=0; i<rowCount; i++){
  21.                     var row = table.rows[1];
  22.                     if(null != row) {
  23.                         //if (rowCount <=1){
  24.                         // alert("cannot delete");
  25.                         // break;
  26.                         //}
  27.                         table.deleteRow(1);
  28.                         //rowCount--;
  29.                         //i--;
  30.                     }
  31.                 }catch(e) {
  32.                     alert(e);
  33.                 }
  34.             }
  35.     </script>
  36.     </head>
  37.     <body>
  38.         <TABLE id="dataTable" width="350px" border="1">
  39.             <TR>
  40.                 <s:file id="Upload" label="File " />
  41.             </TR>
  42.         </TABLE>
  43.         <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
  44.         <INPUT type="button" value="Delete" onclick="deleteRow('dataTable')" />
  45.     </body>
  46. </html>  
Sep 17 '10 #5
RamananKalirajan
607 512MB
You can easily do that. I have just modified the deleteRow function.

Expand|Select|Wrap|Line Numbers
  1. function deleteRow(tid){
  2.               var tblObj = document.getElementById(tid);
  3.               var rowLen = tblObj.rows.length;
  4.               if(rowLen>1)
  5.               {
  6.                 alert("Coming Here");
  7.                 tblObj.deleteRow(rowLen-1);   
  8.               }
  9.           }
Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #6
madhuriks
149 100+
hi gud mrng RamananKalirajan,
thanks a lot for ur reply..i had done what u suggested..it is wrking fine..i had another doubt that if i click add button it is not getting it exacltly under browse button it is getting left side of the screen..can u provide me how to do..i had done alignments but not getting cn u tell me.
Sep 17 '10 #7
RamananKalirajan
607 512MB
Can you give a screenshot for that. I was not able to get what you are trying to say.

Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #8
madhuriks
149 100+
hi,
im unable to attach the screen shot.cn u provide me hw to do.
Sep 17 '10 #9
madhuriks
149 100+
hi i attached the screenshot cn u look it.
Attached Files
File Type: zip Doc.zip (95.4 KB, 58 views)
Sep 17 '10 #10
RamananKalirajan
607 512MB
If you click "post reply". You will see containers "Reply to Thread", "Additional Options". In Additional Options there is a section called Attach Files. In that there will be a button "Manage Attachment". Use that.

Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #11
madhuriks
149 100+
i had attached the screen shot cn u look it nd provide me the solution
Sep 17 '10 #12
RamananKalirajan
607 512MB
Hi Madhuriks,
The problem is there are two columns in the default row. But in the newly added ow you are just adding only one columns. Thats why the file input is aligned in the left side. In the addRow() function insert two cells insertCell(0) and insertCell(1). In the first one just add '&nbsp;' and in the second one insert the button.

Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #13
madhuriks
149 100+
i didnt get wht u suggested..cn u provide me the coding part
Sep 17 '10 #14
RamananKalirajan
607 512MB
Expand|Select|Wrap|Line Numbers
  1.     function addRow(tid) {
  2.                 var table = document.getElementById(tid);
  3.                 var rowCount = table.rows.length;
  4.                 var row = table.insertRow(rowCount);
  5.                 var cell0 = row.insertCell(0); 
  6.                 cell0.innerHTML="&nbsp;";
  7.                 var cell1 = row.insertCell(1);
  8.                 var element1 = document.createElement("input");
  9.                 element1.type = "file";
  10.                 cell1.appendChild(element1);
  11.             }
Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #15
madhuriks
149 100+
hi,
i had attached the screen shot.in that im getting added browse buttons after 'Add','Delete' and 'Upload' buttons..but i need it immediately after first browse button..can u chk it where it goes wrong..here is the code.
Expand|Select|Wrap|Line Numbers
  1. <div id="div2">
  2.                 <table id="contentTable" align="center" width=610 cellspacing=0 cellpadding=3 border="0" style="border:1px solid gray">
  3.                     <s:select name="AppType" id="UploadAppType" label="Application Type" headerKey="1" headerValue="-- Please Select --"
  4.                               list="#{'01':'SIS','02':'Jar','03':'SISX','04':'APK','05':'SIS60','06':'SIS9'}" />
  5.                     <tr>
  6.                         <td>
  7.                         <s:file name="AppContent" id="UploadAppFile" label="Application File " />
  8.                         </td>
  9.                     </tr>
  10.                     <tr align="center"><td align=center colspan=2 class=cell>
  11.                             <input type="button" value="Add" onclick="contentTableAdd('contentTable');">
  12.                             <input type="button" value="Delete" onclick="contentTableDelete('contentTable');">
  13.                         </td></tr>
  14.                         <s:submit label="Upload" value="Upload" align="center" />
  15.                 </table>
  16.             </div>
Attached Files
File Type: zip Doc.zip (102.9 KB, 57 views)
Sep 17 '10 #16
RamananKalirajan
607 512MB
Try this content

Expand|Select|Wrap|Line Numbers
  1. <div id="div2">
  2.    <table align="center" width=610 cellspacing=0 cellpadding=3 border="0" style="border:1px solid gray">
  3.       <tr>
  4.         <td>
  5.            <s:select name="AppType" id="UploadAppType" label="Application Type" headerKey="1" headerValue="-- Please Select --"
  6.                               list="#{'01':'SIS','02':'Jar','03':'SISX','04':'APK','05':'SIS60','06':'SIS9'}" />
  7.         </td> 
  8.       </tr>
  9.       <tr>
  10.          <td>
  11.             <table id="contentTable" align="center" width=610 cellspacing=0 cellpadding=0 border="0"> 
  12.                 <tr>
  13.                   <td>
  14.                      <s:file name="AppContent" id="UploadAppFile" label="Application File " />
  15.                   </td>
  16.                 </tr>
  17.             </table>
  18.          </td>
  19.       </tr>
  20.       <tr>
  21.          <td align=center class=cell>
  22.             <input type="button" value="Add" onclick="contentTableAdd('contentTable');">
  23.             <input type="button" value="Delete" onclick="contentTableDelete('contentTable');">
  24.          </td>
  25.       </tr>
  26.       <tr>
  27.          <td>
  28.             <s:submit label="Upload" value="Upload" align="center" />
  29.          </td>
  30.       </tr>
  31.    </table>  
  32. </div>
Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #17
madhuriks
149 100+
hi,
i got it what i need..can u tell me tht add and delete should come aside browse button..i tried to place but it is not getting cn u tell me how to do
Sep 17 '10 #18
RamananKalirajan
607 512MB
Replace this
Expand|Select|Wrap|Line Numbers
  1.  <td align=center class=cell>
  2.              <input type="button" value="Add" onclick="contentTableAdd('contentTable');">
  3.              <input type="button" value="Delete" onclick="contentTableDelete('contentTable');">
  4.           </td>
with
Expand|Select|Wrap|Line Numbers
  1.  <td align=center class=cell>
  2.  <table width="610" cellspacing="0" cellpadding="0" border="0">
  3.  <tr>
  4.    <td>
  5.         &nbsp;
  6.    </td>
  7.    <td>
  8.              <input type="button" value="Add" onclick="contentTableAdd('contentTable');">
  9.              <input type="button" value="Delete" onclick="contentTableDelete('contentTable');">
  10.   </td></tr></table>
  11.           </td>
Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #19
madhuriks
149 100+
hi gud afternoon,
i had wht u suggested but i need the 'Add' and 'Delete' buttons should come in one line i.e.,'Browse' 'Add' 'Delete'..cn u suggest me..here is the screen shot
Attached Files
File Type: zip Doc.zip (102.0 KB, 53 views)
Sep 17 '10 #20
RamananKalirajan
607 512MB
in the "td" which contains those button give align = "right" or style="margin-left:12opx;". This will do

Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #21
madhuriks
149 100+
i had done but im not getting..it getting down the first browse button
Sep 17 '10 #22
RamananKalirajan
607 512MB
Sorry yaar i was not able to help you out.

Thanks and Regards
Ramanan Kalirajan
Sep 17 '10 #23
madhuriks
149 100+
its k RamananKalirajan, thanks for the support till nw.
Sep 17 '10 #24

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Lau Lei Cheong | last post: by
6 posts views Thread by Terry | last post: by
1 post views Thread by Varun Kacholia | last post: by
2 posts views Thread by rudranee | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.