My programming days are long gone.. didnt do much js but trying to help a friend.
the question “how to find the max value in a html table”
for instance.. I have x number rows with col1 being Name and Col2 being a total. the task is to find the Name with the Max Col2.
I started this but running into problems (in this situation I want to write the value 3 ) :
<html>
<head>
<script type=”text/javascript”>
function changeContent()
{
var max = 0;
var newvalue = 0;
var i = 0;
for (i=0; document.getElementById(‘myTable’).rows; i++)
{ newvalue=document.getElementById(‘myTable’).rows[i].cells
if (newvalue[1] > max)
{ max = newvalue[1];
}
}
document.writeln(max)
}
</script>
</head>
<body>
<table id=”myTable” border=”1″>
<tr>
<td>Row1 cell1</td>
<td>1</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>3</td>
</tr>
</table>
<form>
<input type=”button” onclick=”changeContent()” value=”Change content”>
</form>
</body>
</html>