change the text box name

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

    change the text box name

    I don't know how to change the text box 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)

    remainder rows, after delete.

    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?

    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;      // serial no  
        
        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]. 
    }
    the alert message is "[object HTMLInputElemen t] [object HTMLInputElemen t] [object HTMLInputElemen t] "



    Thanks & Regards,
    Susan.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by shivasusan


    the alert message is "[object HTMLInputElemen t] [object HTMLInputElemen t] [object HTMLInputElemen t] "
    Then why did you lie me?

    Code:
    aRow.name = ('txt_C' + k); 
    FDate.name = ('txt_F' + k); 
    TDate.name = ('txt_T' + k);
    Are not these three lines not working?

    Comment

    • shivasusan
      New Member
      • Oct 2008
      • 67

      #3
      Yes.. i got error message.... aRow.name = ('txtc' + k) is null.

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        have a look this code....

        Code:
        function test(){
         var text_box_ref = document.getElementById('text_box');
         alert(document.getElementsByName('text_box')[0]); //before changing the name
         text_box_ref.name = 'new_text_box';
         alert(document.getElementsByName('text_box')[0]); //after changing the name
         alert(document.getElementsByName('new_text_box')[0]);
        }
        Code:
        <body onload="test()">
        <input type=text id="text_box" name="text_box" value="Debasis Jana"/>
        </body>
        Test it .... where i am changing the name then trying to access with old name.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Are you by any chance having problems with IE? IE does not allow you to set the name (at least not properly). There is a workaround though.

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by acoder
            Are you by any chance having problems with IE? IE does not allow you to set the name (at least not properly). There is a workaround though.
            Hey i didn't check with IE..just only tested in Mozilla ;)
            But i think he didn't work with IE, see at his alerts .... "HTMLInputEleme nt" ;)

            Comment

            • shivasusan
              New Member
              • Oct 2008
              • 67

              #7
              Hi

              pls check my code is below:

              Code:
              for(var k=i;k<lastRow-1;k++){ 
              
               var aRow = document.getElementById('txtc' + k); 
              // var FDate = document.getElementById('txtf' + (k+1)); 
               //var TDate = document.getElementById('txtt' + (k+1)); 
              
                  tbl.rows[k].cells[0].innerHTML = (k-1)+1; 	
              	alert(document.getElementByName('txtc' + k)[0]);  
              	aRow = "new_Name";
              	alert(document.getElementByName('txtc'+k)[0]);  
              	alert(document.getElementByName('new_Name')[0]); 
              }
              i got error on this line "alert(document .getElementByNa me('txtc' + k)[0]); "

              i thought my code is wrong.

              Thanks & Regards,
              Susan.

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5388

                #8
                there is no method called:

                [CODE=javascript]getElementByNam e()[/CODE]
                it's:
                [CODE=javascript]getElementsByNa me()[/CODE]
                kind regards

                Comment

                • shivasusan
                  New Member
                  • Oct 2008
                  • 67

                  #9
                  Hi!

                  I was changed...."get ElementsByName( )", but I didn't got the answer. The alert message display "undefine"
                  Code:
                  getElementsByName()
                  pls help me..

                  Thanks & Regards,
                  Susan.

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5388

                    #10
                    it will not work with IE ... since IE doesn't allow to change the name-attribute at runtime ... do you encounter this problem in IE?

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      You've set aRow (the object) to a string. What you meant to do was set its name:
                      Code:
                      aRow.name = "new_Name";

                      Comment

                      • shivasusan
                        New Member
                        • Oct 2008
                        • 67

                        #12
                        Hi!

                        tbl.rows[k].cells[0].innerHTML ---- display the inner value of the text node.

                        by using this way, i want to get the text box value. how?

                        i try like this:
                        Code:
                        tbl.rows[k].cells[0].value
                        pls reply to me immed....

                        Thanks & Regards,
                        Susan.

                        Comment

                        • dmjpro
                          Top Contributor
                          • Jan 2007
                          • 2476

                          #13
                          Code:
                          alert(tbl.rows[k].cells[0].innerHTML.getElementsByTagName('input')[0].value);
                          //check what does it say?

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            wouldn't
                            Code:
                            alert(tbl.rows[k].cells[0].getElementsByTagName('input')[0].value);
                            suffice?

                            Comment

                            • shivasusan
                              New Member
                              • Oct 2008
                              • 67

                              #15
                              Hi!

                              yes.... i changed the the name for the text box.

                              now i got the error in validateRow(). how to solve?

                              delete row code:
                              Code:
                              for(var k=i;k<lastRow-1;k++){ 
                              
                               
                                 tbl.rows[k].cells[0].innerHTML = (k-1)+1; 	 /// serial no.
                              tbl.tBodies[0].rows[k].myRow.two.name = 'txtc'+ k; // input text country
                              	tbl.tBodies[0].rows[k].myRow.three.name = 'txtf'+ k; // input text from date
                              	tbl.tBodies[0].rows[k].myRow.four.name = 'txtt'+ k; // input text to date

                              Code:
                              function validateRow(frm)
                              {
                                  var tbl = document.getElementById('tblSample');
                                  var lastRow = tbl.rows.length - 1;
                              	//alert (lastRow);
                                  var i;
                                  for (i=1; i<=lastRow; i++) {
                              		
                              	var aRow = document.getElementById('txt_C+i);  ---- i got error on this line
                              	var FDate= document.getElementById('txt_F' + i).value;  ---- i got error on this line
                              	var TDate = document.getElementById('txt_T' + i).value;  ---- i got error on this line
                              
                                   if (aRow.value.length <= 0) {
                                      alert('Row ' + i + ' is empty');
                                      return;
                                    }
                              
                              if (FDate>TDate) {
                                      alert("You have entered the date incorrectly on Row '" + i +"', please make the necessary amendments0.");
                                      return;
                              	  }	
                                  }
                              error message is:
                              document.getEle mentById("txt_C " + i) is null
                              var aRow = document.getEle mentById('txt_C ' + i).value;
                              pls reply to me immmm...
                              Thanks & Regards,
                              Susan.

                              Comment

                              Working...