how to change id by adding new row..

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: how to change id by adding new row..

 
0
  #11
Aug 11th, 2009
If all is working fine then you can use rowIndex as generating id.

  1. function add(oRow)
  2. {
  3. var selObj = oRow.getElementsByTagName('select')[0];
  4. if(selObj[0].selected){ // Check for empty ledger entry
  5. alert("Please select ledger");
  6. return false;
  7. }
  8. oRow.parentNode.replaceChild(oRow.cloneNode(true),oRow.parentNode.insertRow(oRow.rowIndex+1));
  9. var inpR = oRow.getElementsByTagName('input');
  10. var inpN = oRow.nextSibling.getElementsByTagName('input');
  11. // Setting id
  12. inpN.id = 'textBox_' + oRow.rowIndex+1;
  13. var selR = oRow.getElementsByTagName('select')[0];
  14. selR.disabled=true;
  15. var selN = oRow.nextSibling.getElementsByTagName('select')[0];
  16. selN.selectedIndex=0;
  17. for(i=0;i<inpR.length;i++)
  18. {
  19. if(inpR[i].disabled){inpR[i].disabled=false;/**/};
  20. if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value='';inpN[i].disabled=false};
  21. if(inpR[i].value=='Add'){inpR[i].value='Edit';inpN[i].disabled=true};
  22. } sumus();knockOut(selN);
  23. }
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster in Training

Re: how to change id by adding new row..

 
0
  #12
Aug 11th, 2009
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. inpN.id = 'textBox_' + oRow.rowIndex+1;
.
.
this code doesnt showing or creating any ID.. :O
Last edited by sam023; Aug 11th, 2009 at 2:21 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 818
Reputation: Airshow is on a distinguished road 
Solved Threads: 116
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: how to change id by adding new row..

 
0
  #13
Aug 11th, 2009
Originally Posted by Luckychap View Post
If all is working fine then you can use rowIndex as generating id.
That's fine the first time a row is cloned but on a second cloning of the same row, would it not generate an identical id to the first?

That's why I advocate maintaining a counter.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: how to change id by adding new row..

 
0
  #14
Aug 11th, 2009
Originally Posted by sam023 View Post
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. inpN.id = 'textBox_' + oRow.rowIndex+1;
.
.
this code doesnt showing or creating any ID.. :O
Sorry for typo it must be:

  1. inpR.id = 'textBox_' + oRow.rowIndex+1
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: how to change id by adding new row..

 
0
  #15
Aug 11th, 2009
Originally Posted by Airshow View Post
That's fine the first time a row is cloned but on a second cloning of the same row, would it not generate an identical id to the first?

That's why I advocate maintaining a counter.

Airshow
Well if rowIndex is same always, then inpN.length can be used to set ids:

  1. inpR.id = 'textBox_' + inpN.length + 1;

If this does not work, you have to use some sort of counter as suggested by Airshow.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster in Training

Re: how to change id by adding new row..

 
0
  #16
Aug 17th, 2009
none of the code is working..
.
.
can anybody tell how to use counter..? :O
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 348
Reputation: Troy III will become famous soon enough Troy III will become famous soon enough 
Solved Threads: 42
Troy III's Avatar
Troy III Troy III is offline Offline
Posting Whiz

Re: how to change id by adding new row..

 
0
  #17
Aug 17th, 2009
... + i++
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster in Training

Re: how to change id by adding new row..

 
0
  #18
Aug 17th, 2009
didnt get u.. :O
be more specific..
thank you
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 83
Reputation: nish123 is an unknown quantity at this point 
Solved Threads: 0
nish123's Avatar
nish123 nish123 is offline Offline
Junior Poster in Training

Re: how to change id by adding new row..

 
0
  #19
Aug 17th, 2009
I dont think it is possible to change Id.. by using CloneNode...!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 818
Reputation: Airshow is on a distinguished road 
Solved Threads: 116
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: how to change id by adding new row..

 
0
  #20
Aug 17th, 2009
Sam023,

Nish is right, CloneNode doesn't have an option for changing ID(s).

Have you tried the idea in my post #3 of this topic? It outlines a way (certainly not the only way) maintain a counter by which cloned elements can be force-renumbered for uniqueness.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC