I need to give a number sequence (N) when I the user enters the job code. If the user deletes one of the rows (Example number 2) the sequence number of the next Job Code will be the number that is nissing on the current sequence (in this case number 2)
Hi!
If the user deletes one of the rows (Example number 2) the sequence number of the next Job Code will be the number that is nissing on the current sequence (in this case number 2)
it depends on the function which deletes the row and it depends on the HTML code. Post the codes.
The form is in the attache file .... sorry te code is too big.
The ideia is when the user fill the "Job Code" the Javascript will give a sequence number "N".
The form will have 50 rows.
If the user deletes one or more rows then when filling the new row Javascript has to search for the missing numbers on form and add the lowest value.
I was trying to have one array size 50 and then compare with the existing values on the form.
OK. If you posted your problem in words, i have no chance than to respond in the same way:
The idea is:
- the rows in a table have, each, a JavaScript property called rowIndex
- after you delete a row you must rewrite the content of those cells (each second cell in rows) as being equal with the rowIndex of their parent rows - except for the header, where you must let the cell as it is.
Without knowing the custom syntax of your table it is hard to come with a code.
function getSubfID () {
Var BTsize = 50;
var sequen = new Array(BTsize-1);
Var ffound = '0';
for (var i = 0 ; i < sequen.length ; i++){
sequen[i] = i+1;
}
// filling the array with the 50 number sequence
for (int = 0;int < BTsize; ++int) {
fstrlength = '0000'+int;
fstrlength = fstrlength.length;
fPRE = 'subform_jobs' + ('0000'+int).substring(fpstrlength-4);
fvalue = Number(document.getElementById(fPRE+'jobs_num').value);
if ((ffound == 0) and (fvalue != sequence[i])){
document.getElementById(nuGetRow()+'jobs_num').value = sequence[i];
// Give the actual job num field the lowest available sequence number
}
}
}
}
}
Hi Kor,
Thank you for your answer!
Following your example I have add an empty row:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Style-Type" content="text/css"><meta http-equiv="Content-Script-Type" content="text/javascript"><script type="text/javascript">
function delRow(a){
var row=a.parentNode.parentNode;
var tbody=row.parentNode;
tbody.removeChild(row);
var allRows=tbody.getElementsByTagName('tr'), r, i=1;
while(r=allRows[i++]){
r.getElementsByTagName('td')[1].firstChild.nodeValue=r.rowIndex;
}
}
</script></head><body><table border="1"><tr><td>Jobs Code</td><td>N</td><td></td></tr><tr><td>73489573485</td><td>1</td><td><a href="#" onclick="delRow(this);return false">delete row</a></td></tr><tr><td>64654646544</td><td>2</td><td><a href="#" onclick="delRow(this);return false">delete row</a></td></tr><tr><td>53534554355</td><td>3</td><td><a href="#" onclick="delRow(this);return false">delete row</a></td></tr><tr><td>63645654667</td><td>4</td><td><a href="#" onclick="delRow(this);return false">delete row</a></td></tr><tr><td></td><td></td><td><a href="#" onclick="delRow(this);return false">delete row</a></td></tr></table></body></html>
1 - when the user fill the empty job code cell, javascript has to put in the cell "N" the next sequence number ... in this case ..5.
2 - But if first you have deleted row 2 ... the next sequence number is the number that is missing on the form ... so javascript has to put number 2 in the last cell "N".
Bookmarks