|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
adding fields dynamically and then editing
there is a add button(on main page) whenever the user clicks on that a window opens with say 5 fields.
when that is submitted the rows display on the main page. this way user can add any number of rows. there is no problem till here. But with every row there displays a EDIT link. When the user clicks that link corresponding row is displayed in another window where editing can be done. After submitting the changes are shown on the main page this is my main page <html> <head> <script language="JavaScript"> </script> </head> <body> <form name='form1' > <DIV id="mydiv"> </DIV> <input type="button" value="Add New" name="B1" onclick='winnew=window.open("child.jsp","jsp","width=600,height=500,scrollbar=yes"); winnew.focus'> </form> </body> </html> when button is pressed this window opens child.jsp <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> var ctr = 1001; function addTextbox() { var temp = ctr + 1; var next_index = ctr + 2; var next2_index = ctr +3; var next3_index = ctr +4; var next4_index = ctr +5; var next5_index = ctr +6; var next6_index = ctr +7; var next7_index = ctr +8; var next8_index = ctr +9; var next9_index = ctr +10; var val0 = document.myform.T0.value; var val1 = document.myform.T1.value; var val2 = document.myform.T2.value; var val3 = document.myform.T3.value; var val4 = document.myform.T4.value; var val5 = document.myform.T5.value; var val6 = document.myform.T6.value; var val7 = document.myform.T7.value; var val8 = document.myform.T8.value; self.opener.document.getElementById("mydiv").innerHTML += '<TABLE><TR><TH>Material Specification</TH><TH>Purpose</TH> <TH>Qty. in Stock</TH><TH>Qty Reqd.</TH><TH>When Delivery Reqd.</TH><TH>Approx. cost</TH><TH>Vendor</TH><TH>Remarks</TH><TH>Category</TH></TR><TR><TD><INPUT type="text" name="val'+ctr+'" value="'+val0+'"></TD><TD> <INPUT type="text" name="text2'+ctr+'" value="'+val1+'"></TD><TD> <INPUT type="text" name="text3'+ctr+'" value="'+val2+'"></TD><TD><INPUT type="text" name="text4'+ctr+'" value="'+val3+'"></TD><TD><INPUT type="text" name="text5'+ctr+'" value="'+val4+'"> </TD><TD> <INPUT type="text" name="text6'+ctr+'" value="'+val5+'"></TD><TD><INPUT type="text" name="text7'+ctr+'" value="'+val6+'"></TD><TD><INPUT type="text" name="text8'+ctr+'" value="'+val7+'"></TD><TD><INPUT type="text" name="text9'+ctr+'" value="'+val8+'"></TD><TD><a href="#" onclick = window.open("editForm.jsp?i='+boxctr+'&val0='+val0+'&val1='+val1+'&val2='+val2+'&val3='+val3+'&va l4='+val4+'&val5='+val5+'&val6='+val6+'&val7='+val7+'&val8='+val8+'","Edit","height=500,width=600 ")> Edit</a> </TD></TABLE>'; ctr = ctr+9; window.close(); } </script> </head> <body> <FORM name="myform" ACTION="localRequest.jsp" method="post" > <div id="Folder2" class="folder" style="position:absolute; left:20px; top:77px; width:500px; height:300px; z-index:2; overflow:auto"> <BR> <TABLE border="2"> <TR> <TH align='left'>Material Specification/technical(if any)</TH> <TH>Purpose</TH> </TR> <TR> <TD><TEXTAREA style="overflow:hidden" NAME="T0" ROWS="5" COLS="30"></TEXTAREA></TD> <TD><TEXTAREA style="overflow:hidden" NAME="T1" ROWS="5" COLS="30"></TEXTAREA></TD> </TR> <TR> <TH>Qty in Stock</TH> <TH>Qty Reqd</TH> </TR> <TR> <TD ALIGN='CENTER'><INPUT TYPE="text" name="T2"></TD> <TD ALIGN='CENTER'><INPUT TYPE="text" name="T3"></TD> </TR> <TR> <TH>When Delivery Required</TH> <TH>Approx Cost</TH> </TR> <TR> <TD ALIGN='CENTER'><INPUT TYPE="text" name="T4" READONLY></TD> <TD ALIGN='CENTER'><INPUT TYPE="text" name="T5"></TD> </TR> <TR> <TH>Vendor</TH> <TH>Remarks</TH> </TR> <TR> <TD><TEXTAREA style="overflow:hidden" NAME="T6" ROWS="5" COLS="30"></TEXTAREA></TD> <TD><TEXTAREA style="overflow:hidden" NAME="T7" ROWS="5" COLS="30"></TEXTAREA></TD> </TR> <TR> <TH>Category</TH> <TH></TH> </TR> </TABLE> <table> <tr> <td> <a href="#" onclick="addTextbox();">Add</a> </td> </tr> </table> </div> </form> </body> </html> till here there is no problem. the problem comes in editing. The values from child.jsp are passed from editForm.jsp but changed values i ma unable to pass back to the main page because when ever the function addtextbox is callled it give same id to text fields in different rows so changes go back to the first row only. |
|
#2
|
||||
|
||||
|
Did you post the code for editform.jsp? I'm having trouble reading what you posted (by the way, you can separate code from your post by using the {code} {/code} tags, replacing curly braces with square braces. Oh, and why not just do this server-side, having the small window make the changes and refresh the main window?
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > adding fields dynamically and then editing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|