Web Analytics Made Easy -
StatCounter Sort input names from a table - CodingForum

Announcement

Collapse
No announcement yet.

Sort input names from a table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sort input names from a table

    Hello,

    i've got a problem, I try to sort the following code by the input field names. I want it sorted by the numbers, CELL[0], CELL[1] to CELL[x]...

    If I add a row, or move rows, it should re-sort the input fields every time releated to the 'name' value (CELL[x])..

    Anyone got an idea how to do it and maybe a samplescript?

    Ty

  • #2
    Oh, here the code I've made so far:

    Code:
    <script>
    var i = 1
    
    function addRow(src, cells) {
             i++
             var oRow = src.parentElement.parentElement;
    	newcelln = oRow.rowIndex+1
    
    	var newRow = document.all("TABLE_TAT_01").insertRow(newcelln);
    	var oCell = newRow.insertCell();
    
    	oCell.innerHTML = "<input type='text' name='tableDataIndexed["+ i +"].value1' size='15'>";
    
    	oCell = newRow.insertCell();
    	oCell.innerHTML = "<input type='text' name='tableDataIndexed["+ i +"].value2' size='15'>";
    
    	oCell = newRow.insertCell();
    	oCell.innerHTML = "<input type='text' name='tableDataIndexed["+ i +"].value3' size='15'>";
    
    	oCell = newRow.insertCell();
    	oCell.innerHTML = "<input type='button' value='Add Row' onclick='addRow(this);'>&nbsp;<input type='button' value='Delete' onclick='removeRow(this);'>&nbsp;<input type='button' value='Move up' onclick='moveRowUp(this);'>&nbsp;<input type='button' value='Move down' onclick='moveRowDown(this);'>";
    }
    
    function removeRow(src) {
    	var oRow = src.parentElement.parentElement;
    	document.all("TABLE_TAT_01").deleteRow(oRow.rowIndex);
    }
    
    function moveRowUp(src) {
    	var oRow = src.parentElement.parentElement;
             newcellnMove = oRow.rowIndex-1
    	document.all("TABLE_TAT_01").moveRow(oRow.rowIndex, newcellnMove);
             sortTable(oRow.rowIndex, TABLE_TAT_01);
    }
    
    function moveRowDown(src) {
    	var oRow = src.parentElement.parentElement;
             newcellnMove = oRow.rowIndex+1
    	document.all("TABLE_TAT_01").moveRow(oRow.rowIndex, newcellnMove);
    }
    </script>
    
    </head>
    <body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
    
    <form method="POST">
    <table id="TABLE_TAT_01" width="40%">
    <tr>
    <td width="20%"><input type="text" name="tableDataIndexed[0].value1" size="15"></td>
    <td width="20%"><input type="text" name="tableDataIndexed[0].value2" size="15"></td>
    <td width="20%"><input type="text" name="tableDataIndexed[0].value3" size="15"></td>
    <td width="40%"><input type='button' value='Add Row' onclick='addRow(this);'>&nbsp;<input type='button' value='Delete' onclick='removeRow(this);'>&nbsp;<input type='button' value='Move up' onclick='moveRowUp(this);'>&nbsp;<input type='button' value='Move down' onclick='moveRowDown(this);'></td>
    </tr>
    </table>
    Attached Files

    Comment

    Working...
    X