I am using a client-side table sorting script that i found on the internet. It works perfectly, but i have a hit a problem.
In my table, it displays user data, with a link to their details. This link is in the form of an input button within a form.
Eg
[code=php]
<tr>
<td>
Name
</td>
<td>
Surname
</td>
<td>
<form action = “UserDetails.php” method = “post”>
<input type = “hidden” value = “LoginID” />
<input type = “submit” value = “LoginID” />
</form>
</td>
</tr>
The existing javascript just compares values between td tags, but if theres any other tags within the td’s, it causes an error.
The part of the script that performs the row comparison is below.
[code=php]
function rowCompare(a, b) {
var aVal = a.getElementsByTagName(‘td’)[sortedOn].firstChild.nodeValue.toLowerCase();
var bVal = b.getElementsByTagName(‘td’)[sortedOn].firstChild.nodeValue.toLowerCase();
return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
}
is there any way to expand this so that during the row comparison, if a form tag is found then the value of the hidden input within that form is used as the value for the comparison?
Heres an idea of what i mean, extending the above example slightly:
[code=php]
function rowCompare(a, b) {
//check to see if types are input
if(a.getElementsByTagName(‘td’)[sortedOn].firstChild.nodeName == “INPUT”)
{
var aVal = a.getElementsByTagName(‘td’)[sortedOn].firstChild.getAttributeNode(“value”).value.toLowerCase();
}else{
var aVal = a.getElementsByTagName(‘td’)[sortedOn].firstChild.nodeValue.toLowerCase();
}
if(b.getElementsByTagName(‘td’)[sortedOn].firstChild.nodeName == “INPUT”)
{
var bVal = b.getElementsByTagName(‘td’)[sortedOn].firstChild.getAttributeNode(“value”).value.toLowerCase();
}else{
var bVal = b.getElementsByTagName(‘td’)[sortedOn].firstChild.nodeValue.toLowerCase();
}
return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
}
..but the above code doesn’t work properly.
Can anyone help me on this issue?