| | |
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
![]() |
•
•
Join Date: Jun 2009
Posts: 119
Reputation:
Solved Threads: 2
i am making a table with dynamic increament of rows on click of button..!!
i have used an autocomplete textbox in a row...!!! which is based on textbox id..!!
.
.
as i know that id should be unique.. so how can i change ID then..?
i have used an autocomplete textbox in a row...!!! which is based on textbox id..!!
.
.
as i know that id should be unique.. so how can i change ID then..?
javascript Syntax (Toggle Plain Text)
function add(oRow) { var selObj = oRow.getElementsByTagName('select')[0]; if(selObj[0].selected){ // Check for empty ledger entry alert("Please select ledger"); return false; } oRow.parentNode.replaceChild(oRow.cloneNode(true),oRow.parentNode.insertRow(oRow.rowIndex+1)); // alert(oRow.rowIndex+1); var inpR = oRow.getElementsByTagName('input'); var inpN = oRow.nextSibling.getElementsByTagName('input'); var selR = oRow.getElementsByTagName('select')[0]; //alert(selR); selR.disabled=true; var selN = oRow.nextSibling.getElementsByTagName('select')[0]; selN.selectedIndex=0; for(i=0;i<inpR.length;i++) { if(inpR[i].disabled){inpR[i].disabled=false;/**/}; if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value='';inpN[i].disabled=false}; if(inpR[i].value=='Add'){inpR[i].value='Edit';inpN[i].disabled=true}; } sumus();knockOut(selN); }
Last edited by sam023; Aug 10th, 2009 at 4:02 am.
Sam,
If you never use document.getElementById on an element (or otherwise need to read its id) then it doesn't need one.
However, if an elememt does need an id, then as you say, it should be unique. One way to ensure uniqueness in a cloned element is to add a suffix, '_n' (where n is an integer). To ensure that "n" is unique, maintain an invisible counter in each of your table rows and increment it each time the row is duplicated.
Before duplicating the row:
Now clone the row, then:
Now append suffix to all elements in the new row that need it.
New ids will be unique provided that each original id:
If you never use document.getElementById on an element (or otherwise need to read its id) then it doesn't need one.
However, if an elememt does need an id, then as you say, it should be unique. One way to ensure uniqueness in a cloned element is to add a suffix, '_n' (where n is an integer). To ensure that "n" is unique, maintain an invisible counter in each of your table rows and increment it each time the row is duplicated.
Before duplicating the row:
javascript Syntax (Toggle Plain Text)
var n = oRow.getAttribute('counter'); n = (n===null) ? 0 : n+1; oRow.setAttribute('counter', n);
javascript Syntax (Toggle Plain Text)
var suffix = '_' + n; newRow.setAttribute('counter', 0);//Set to 0 in case the cloned row is itelf later cloned.
New ids will be unique provided that each original id:
- is unique
- is not of a value that could possibly occur due to the renumbering of another.
50% of the solution lies in accurately describing the problem!
javascript Syntax (Toggle Plain Text)
function add(oRow) { var selObj = oRow.getElementsByTagName('select')[0]; if(selObj[0].selected){ // Check for empty ledger entry alert("Please select ledger"); return false; } oRow.parentNode.replaceChild(oRow.cloneNode(true),oRow .parentNode.insertRow(oRow.rowIndex+1)); var inpR = oRow.getElementsByTagName('input'); var inpN = oRow.nextSibling.getElementsByTagName('input'); var selR = oRow.getElementsByTagName('select')[0]; //alert(selR); selR.disabled=true; var selN = oRow.nextSibling.getElementsByTagName('select')[0]; selN.selectedIndex=0; for(i=0;i<inpR.length;i++) { if(inpR[i].disabled){inpR[i].disabled=false;/**/}; if(inpR[i].type=='text'){inpR[i].disabled=true;inpN[i].value='';inpN[i].disabled=false}; if(inpR[i].value=='Add'){inpR[i].value='Edit';inpN[i].disabled=true}; } sumus();knockOut(selN); }
i have a code for autocomplete in one of the textbox in a row.. but for that i need ID..!!
but because of clone i m unable to enter different id..!! where should i maker change in my javascript..!!
Last edited by nish123; Aug 11th, 2009 at 6:54 am.
•
•
Join Date: Jun 2009
Posts: 119
Reputation:
Solved Threads: 2
Yes it is my topic but i can see that nish123 facing the same problem..!! and he also using same code as i do..!!!
so kindly help me out..!! where should i make changes..? in the code to create different id...!!
so kindly help me out..!! where should i make changes..? in the code to create different id...!!
•
•
Join Date: Jun 2009
Posts: 119
Reputation:
Solved Threads: 2
•
•
•
•
I don"t think change ID is a good Idea because in a future you may use they "id" in another cases
as my auto complete function is based on id and ID must be unique..!!
.
.
as the user append the row... the clonenode function create exactly the same row as above including ID..!!! and that thing will create problem...!!!
.
.
can anyone suggest an auto complete function where ID is not required..?
![]() |
Similar Threads
- Adding a new row in a Datagrid ??????????? (C#)
- How to change color of a row (Java)
- Adding new row in DataGrid (C#)
- Trouble adding new row to DataTable (C#) (C#)
- Having problems with adding a row to a DataSet (VB.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: How can we delete array in javascript?
- Next Thread: I want put a clock on my page
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets api blackjack browser bug captchaformproblem checkbox child class close cookies createrange() cursor date debugger dependent developer disablefirebug dom dropdown editor element embed engine events explorer ext file flash form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl maps math matrixcaptcha media mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming progressbar rated runtime safari scriptlets scroll search security session shopping size software solutions star stars stretch synchronous tweet unicode variables web webkit webservice window wysiwyg \n





