/    Sign up×
Community /Pin to ProfileBookmark

form tags in client-side table sorting

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>
[/code]

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));
}

[/code]

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));
}
[/code]

..but the above code doesn’t work properly.
Can anyone help me on this issue?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @moondance spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...