delete row() dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivasusan
    New Member
    • Oct 2008
    • 67

    #16
    Hi!

    Thankyou soo much. I got the answer.

    But i did little bit change.

    Code:
    for(var k=i;k<lastRow-1;k++){ 
     tbl.rows[k].cells[0].innerHTML = (k-1)+1; 
    }
    Thanks & Regards,
    Susan.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #17
      Originally posted by shivasusan

      Code:
       tbl.rows[k].cells[0].innerHTML = (k-1)+1;
      Susan.
      Oh yeah...... That's right. What does it mean (k-1)+1, it means k.
      Let the run time system to do operations as little as possible. Avoid unnecessary operation ;) Glad to see that you did that.

      Comment

      • shivasusan
        New Member
        • Oct 2008
        • 67

        #18
        Hi!

        I don't know how to change the other cells name?

        for ex:(my table like this)

        sl. country from to
        1 aaa (txt_c1) 5/4/09 (txt_f1) 5/13/09 (txt_t1) // Now i delete this row.
        2 bbb (txt_c2) 5/18/09 (txt_f2) 5/25/09 (txt_t2)
        3 ccc (txt_c3) 6/2/09 (txt_f3) 6/15/09 (txt_t3) // now i delete this row.
        4 eee (txt_c4) 7/15/09 (txt_f4) 7/25/09 (txt_t4)

        Now the text box name is:

        1 bbb (txtc_2) 5/18/09 (txt_f2) 5/25/09 (txt_t2) // here i want to change the text box name automatically (txtc_1, txtf_1, txtt_1) how?
        2 eee (txtc_4) 7/15/09 (txt_f4) 7/25/09 (txt_t4) // here i want to change the text box name automatically (txtc_2, txt_f2, txt_t2) how?

        I got this error in validateRow(). in for loop.... (txt_c+i)

        sorry Sir/Madam, i don't know. how to change? pls help me.

        Code:
        function validateRow(frm)
        {
            var tbl = document.getElementById('tblSample');
            var lastRow = tbl.rows.length - 1;
            var i;
        	var compDate,j;
        	
            for (i=1; i<=lastRow; i++) {
              var aRow = document.getElementById('txt_C' + i);
        	  var FDate = document.getElementById('txt_F' + i).value;
        	  var TDate = document.getElementById('txt_T' + i).value;
        	  var country = document.getElementById('txt_C' + i).value; 
        	  var fieldvalue = document.getElementById("chk_travel").value;
        
        	  country = country.toUpperCase();	
        
        
              if (aRow.value.length <= 0) {
                alert('The country ' + i + ' is empty');
                return;
              }
        	  var test;
        	  test = "NIL" 
        	  compDate = TDate - FDate;
        	  
              if (FDate>TDate) {
                alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments0.");
                return;
        	  }	
        	  
        
        	 // else
        	 if (country != test)
        	 {
        	 	if(FDate == "NIL" || TDate == "NIL")
        		{
                alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments1.");
        		return;
        		}
        		
        	 	else if(FDate == "" || TDate == "")
        		{
                alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments2.");
        		return;
        		}
        	}
        		
        			if(fieldvalue == "YES" && country == "NIL"){
        			alert("Please Enter the country name or If you are not Travel please select Not Travelling.");
        			return;
        			}
        	
        	
            }// for loop end
          
          
        	if(document.getElementById('tet_Name_PG').value == "NIL" || document.getElementById('tet_Name_PG').value == "")
        	{
        	alert("Please enter Name of Parent/Guardian. ");
        	return;
        	}
        	
        	var alphaExp = /^[a-zA-Z]+$/;
        	var pgname = document.getElementById('tet_Name_PG').value;
        	if(!pgname.match(alphaExp)){
        		alert("Please enter only characters");
        		return;
        	}
        
        	
        	var cons;
        	cons = document.getElementById('tet_Contact').value;
        	
        	if (!Number(cons)) 
           		{ 
              	alert('Please enter Parent/Guardian Contact no.') 
           //   frm.tet_Contact.focus(); 
              	return; 
              } 
          
        			if(fieldvalue == "NIL"){
        			alert("Please select Travelling or Not Travelling");
        			return;
        			}
        		  	
          frm.submit();
        }
        Thank & Regards,
        Susan.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #19
          First of all why are you changing the name. Having the same name you can retrieve the values easily in server side.

          Anyway... Updating the name is quite easy if you can change the serial no.

          Code:
          for(var i=starting_row_num;i<current_row_nos_after_delete;i++){
           var text_box_ref = .. ;
           text_box_ref.name = 'text'+i;
          }

          Comment

          • shivasusan
            New Member
            • Oct 2008
            • 67

            #20
            Hi!

            Thanks for you reply.

            i try, but i am not understand.

            i wrote this code in remove function. after delete its automatically change the text box name and id. (because my database field name is c1, f1, t1 to c6, f6, t6, so i want to change the field name c1,c2,c3....) pls help me....

            now my doubt is:
            1. how i can get the old text box name?
            2. how i can change the new name for the text box?
            3. i want to change the text box "name" and "id".

            Code:
            for(var k=i;k<lastRow-1;k++){ 
            
             tbl.rows[k].cells[0].innerHTML = (k-1)+1; 
                  var aRow = document.getElementById('txt_C' + k);
            	  var FDate = document.getElementById('txt_F' + k);
            	  var TDate = document.getElementById('txt_T' + k);
            	  
            	  aRow.name = ('txt_C' + k);
            	  FDate.name = ('txt_F' + k);
            	  TDate.name = ('txt_T' + k);
            		
            }
            Thanks & Regards,
            Susan.

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #21
              Originally posted by shivasusan
              Code:
              for(var k=i;k<lastRow-1;k++){ 
              
               tbl.rows[k].cells[0].innerHTML = (k-1)+1; 
                    var aRow = document.getElementById('txt_C' + k);
              	  var FDate = document.getElementById('txt_F' + k);
              	  var TDate = document.getElementById('txt_T' + k);
              	  
              	  aRow.name = ('txt_C' + k);
              	  FDate.name = ('txt_F' + k);
              	  TDate.name = ('txt_T' + k);
              		
              }
              What's the problem with this? Do three elements alert you right object reference if you do alert(aRow+'\t' +FDate+'\t'+TDa te)?
              Why are you accessing those using IDs?
              Simply you can go to the fields using rows[rowIndex].cells[cellIndex].childNodes[...].

              Comment

              • shivasusan
                New Member
                • Oct 2008
                • 67

                #22
                Hi!

                already i checked using alert. its didn't display anything in alert message. but i got error message. "aRow is null (aRow.name = ('txt_C' + k); " so i thought my coding is wrong and i understand wrongly. so i will ask you. how?

                then i don't know any thing in rows[rowIndex].cells[cellIndex].childNodes[....]

                pls help me... now what i can do? how i can solve this error? i did any wrong in my coding?

                Thanks & Regards,
                Susan.

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #23
                  Originally posted by shivasusan
                  Code:
                  for(var k=i;k<lastRow-1;k++){ 
                  
                   tbl.rows[k].cells[0].innerHTML = (k-1)+1; 
                            var aRow = document.getElementById('txt_C' + k);
                  	  var FDate = document.getElementById('txt_F' + k);
                  	  var TDate = document.getElementById('txt_T' + k);
                  	  
                  	  aRow.name = ('txt_C' + k);
                  	  FDate.name = ('txt_F' + k);
                  	  TDate.name = ('txt_T' + k);
                  		
                  }
                  Try with ...
                  Code:
                  var aRow = document.getElementById('txt_C' + (k+1));
                  var FDate = document.getElementById('txt_F' + (k+1));
                  var TDate = document.getElementById('txt_T' + (k+1));
                  I think that would work.

                  Comment

                  • shivasusan
                    New Member
                    • Oct 2008
                    • 67

                    #24
                    Hi!

                    sorry, still i didn't got the answer. today i want to finish this part, so pls help me....

                    the alert message display "null". I don't know, how to solve?

                    Code:
                    for(var k=i;k<lastRow-1;k++){ 
                    
                     var aRow = document.getElementById('txt_C' + (k+1)); 
                    var FDate = document.getElementById('txt_F' + (k+1)); 
                    var TDate = document.getElementById('txt_T' + (k+1)); 
                    
                        tbl.rows[k].cells[0].innerHTML = (k-1)+1; 	  
                    	alert(aRow+'\t'+FDate+'\t'+TDate);
                    	 
                                    // aRow.name = ('txt_C' + k);
                    	 // FDate.name = ('txt_F' + k);
                    	 // TDate.name = ('txt_T' + k);
                    		
                    	//	tbl.rows[k].cells[1].childNodes[1].
                    }

                    change the sr. no. automatically coding below:
                    tbl.rows[k].cells[0].innerHTML = (k-1)+1;

                    how i can change the text box name for country, from and to? where i can place the aRow, FDate and TDate? But i try like this way, it is correct.
                    tbl.rows[k].cells[1].childNodes[1].

                    pls help i want to finish today itself. pls...

                    Thanks & Regards,
                    Susan.

                    Comment

                    • shivasusan
                      New Member
                      • Oct 2008
                      • 67

                      #25
                      Hi!

                      check the tagname "alert(r.parent Node.tagName); "

                      How i can check the textbox name?

                      Comment

                      • dmjpro
                        Top Contributor
                        • Jan 2007
                        • 2476

                        #26
                        Originally posted by shivasusan
                        But i try like this way, it is correct.
                        tbl.rows[k].cells[1].childNodes[1].
                        It should work, but i wonder why document.getEle mentById(..) is not working :(

                        Comment

                        • shivasusan
                          New Member
                          • Oct 2008
                          • 67

                          #27
                          Hi!

                          Yes.... its display null. pls give some idea. i want to finished this part today itself. so i feel very tension.

                          Comment

                          • shivasusan
                            New Member
                            • Oct 2008
                            • 67

                            #28
                            Hi

                            Now the alert message is "[object HTMLInputElemen t] [object HTMLInputElemen t] [object HTMLInputElemen t] "

                            Code:
                            for(var k=i;k<lastRow-1;k++){ 
                            
                             var aRow = document.getElementById('txtc' + (k+1)); 
                             var FDate = document.getElementById('txtf' + (k+1)); 
                             var TDate = document.getElementById('txtt' + (k+1)); 
                            
                                tbl.rows[k].cells[0].innerHTML = (k-1)+1; 	  
                            	alert(aRow+'\t'+FDate+'\t'+TDate);
                            	 // aRow.name = ('txt_C' + k);
                            	 // FDate.name = ('txt_F' + k);
                            	 // TDate.name = ('txt_T' + k);
                            		
                            	//alert(tbl.rows[k].cells[1].innerHTML);
                            }
                            this "alert(tbl. rows[k].cells[1].innerHTML);" --- <input size="40" id="txtc5 name=txtc5" type="Text">

                            pls give me some idea.

                            Thanks & Regards,
                            Susan.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #29
                              Originally posted by shivasusan
                              this "alert(tbl. rows[k].cells[1].innerHTML);" --- <input size="40" id="txtc5 name=txtc5" type="Text">
                              Perhaps that's the problem. The ID is actually "txtc5 name=txtc5", not "txtc5" as you would expect because of the missing quotes.

                              Comment

                              • dmjpro
                                Top Contributor
                                • Jan 2007
                                • 2476

                                #30
                                Originally posted by acoder
                                Perhaps that's the problem. The ID is actually "txtc5 name=txtc5", not "txtc5" as you would expect because of the missing quotes.
                                But i think he fixed up this error. Now it alerts HTMLInputEelmen t.

                                Comment

                                Working...