0

im trying to get the user to enter information into a textbox and then after clicking submit button the page has a table containing with that information in the rows.
so for example the table has the heading Artist, Songs, Year made, Gene
and the user has to enter data for each feild inside a text box and it store it in here.
this is what i have so far

<!DOCTYPE HTML>

<HTML>
<H2>JavaScript Sort Table</H2>
<head>
<script>

    function sortTable(col, myTable){
var cell = col + myTable.cols;
var totalRows = myTable.rows.length;
var tSort = 0;
var columns = new Array();
var index = new Array();
var indexArray = new Array();
var array = new Array();
var newRow;
var newCell;
var i,j,k;
for (i=1; i < myTable.rows.length; i++) {
columns[i - 1] = myTable.cells(cell).innerText;
cell = cell + myTable.cols;
}
for (i=0; i < columns.length; i++){
array[i] = columns[i];
}
columns.sort();
for (i=0; i < columns.length; i++){
indexArray[i] = (i+1);
for(j=0; j < array.length; j++){ 
if (columns[i] == array[j]){ 
for (k=0; k<i; k++){
if ( index[k] == (j+1) ){
tSort = 1;
}
}
if (tSort == 0){
index[i] = (j+1);
}
tSort = 0;
}
}
}
for (i=0; i<index.length; i++) {
newRow = myTable.insertRow();
for (k=0; k<myTable.cols; k++) {
newCell = newRow.insertCell();
newCell.innerHTML = myTable.rows(index[i]).cells(k).innerHTML;
}
}
for (i=1; i<totalRows; i++){
myTable.moveRow((myTable.rows.length -1),1);
}
for (i=1; i<totalRows; i++){
myTable.deleteRow();
}
}


</script>
</head>
<body>

<TABLE WIDTH="55%" BORDER="1" name="table" id="table" cols="4">
<TR><TD><A href="javascript:sortTable(0, table);"><FONT color="red"><B>Artist</FONT></B></A></TD>
<TD><A href="javascript:sortTable(1, table);"><FONT color="red"><B>Songs</FONT></B></A></TD>
<TD><A href="javascript:sortTable(2, table);"><FONT color="red"><B>Year</FONT></B></A></TD>
<TD><A href="javascript:sortTable(3, table);"><FONT color="red"><B>Gene</FONT></B></A>
</TD></TR></FONT>
<TR><TD>Jlo</TD><TD>what goes around</TD><TD>2000</TD><TD>hip hop</TD></TR>
<TR><TD>50 cent</TD><TD>stright to the bank</TD><TD>2003</TD><TD>rap</TD></TR>
<TR><TD>Katy perry</TD><TD>i kissed a girl</TD><TD>2010</TD><TD>pop</TD></TR>
<TR><TD>jay-Z</TD><TD>99 problems</TD><TD>1999</TD><TD>Rap</TD></TR>
</TABLE>
</body>
</HTML>
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by AARTI SHRIVAS
0

So, the code you provided thus far shows a table and a "header" type row that executes a function that is to supposed to sort the column.

Can you elaborate more on what you are trying to do with regard to the text box and the submit button? They werent included in this code. Are you trying to pass data between pages, same page, etc.?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.