dtaylorODIM
Technical User
Hello everyone,
I'm working on a page which displays a table of information from our database. This table can be sorted by clicking on the header on the column by which you want to sort.
A request has come in to make it possible to sort by 2 columns at once and that has given me the opportunity to update it to use POST variables instead of GET variables that give the user too much opportunity to mess around.
I've set this up by having the header links call javascript which updates the form to the correct sort field and then submit.
This was working fine until I copied the same code down to where the headers repeat themselves then it seemed to stop working and undoing the changes did not solve things. For some reason it seems to still work with Firefox but the office uses IE.
Here is the header row (the PHP code just determines if an image should be loaded to show how it is currently sorted):
Here is the javascript function each link calls:
And the html form which is at the bottom of the page after the table (again, the PHP just lets me put in the current sort info):
I've tried putting some alert lines for debugging and they show that the gathered values at the begining are correct and then just before the .submit() is called the new values reflect what it should be.
Then when the page loads it still shows the default sorting. I tried throwing in PHP debugging at the begining of the page:
And it confirms that the information is sent but it's sent with the default values before javascript ran.
So, can anyone think of a reason that the information would revert before the post information is sent?
Thanks,
David I. Taylor
Network Administrator
I'm working on a page which displays a table of information from our database. This table can be sorted by clicking on the header on the column by which you want to sort.
A request has come in to make it possible to sort by 2 columns at once and that has given me the opportunity to update it to use POST variables instead of GET variables that give the user too much opportunity to mess around.
I've set this up by having the header links call javascript which updates the form to the correct sort field and then submit.
This was working fine until I copied the same code down to where the headers repeat themselves then it seemed to stop working and undoing the changes did not solve things. For some reason it seems to still work with Firefox but the office uses IE.
Here is the header row (the PHP code just determines if an image should be loaded to show how it is currently sorted):
Code:
<tr bgcolor=#234567>
<td NOWRAP>
<A HREF='javascript: sort("eco_number")' class=hilighted>ECO No.</A>
<?php
if ($sort1 == 'eco_number' || $sort2 == 'eco_number') {
$order = $sort1 == 'eco_number' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td NOWRAP>
<A HREF='javascript: sort("job_number")' class=hilighted>Job No.</A>
<?php
if ($sort1 == 'job_number' || $sort2 == 'job_number') {
$order = $sort1 == 'job_number' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td NOWRAP>
<A HREF='javascript: sort("product_line")' class=hilighted>Product Line</A>
<?php
if ($sort1 == 'product_line' || $sort2 == 'product_line') {
$order = $sort1 == 'product_line' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td>
<A HREF='javascript: sort("product_version")' class=hilighted>Version</A>
<?php
if ($sort1 == 'product_version' || $sort2 == 'product_version') {
$order = $sort1 == 'product_version' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td>
<A HREF='javascript: sort("eco_desc")' class=hilighted>Description</A>
<?php
if ($sort1 == 'eco_desc' || $sort2 == 'eco_desc') {
$order = $sort1 == 'eco_desc' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td>
<A HREF='javascript: sort("create_date")' class=hilighted>Created</A>
<?php
if ($sort1 == 'create_date' || $sort2 == 'create_date') {
$order = $sort1 == 'create_date' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td width=29><DIV align=center>
<A HREF='javascript: sort("originator")' class=hilighted>By</A>
<?php
if ($sort1 == 'originator' || $sort2 == 'originator') {
$order = $sort1 == 'originator' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</DIV></td>
<td>
<A HREF='javascript: sort("effect_date")' class=hilighted>Effective</A>
<?php
if ($sort1 == 'effect_date' || $sort2 == 'effect_date') {
$order = $sort1 == 'effect_date' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td NOWRAP>
<A HREF='javascript: sort("importance")' class=hilighted>Imp!</A>
<?php
if ($sort1 == 'importance' || $sort2 == 'importance') {
$order = $sort1 == 'importance' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td NOWRAP>
<A HREF='javascript: sort("inhouse_part_change")' class=hilighted>IPC</A>
<?php
if ($sort1 == 'inhouse_part_change' || $sort2 == 'inhouse_part_change') {
$order = $sort1 == 'inhouse_part_change' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td NOWRAP>
<A HREF='javascript: sort("research_work")' class=hilighted>R&D</A>
<?php
if ($sort1 == 'research_work' || $sort2 == 'research_work') {
$order = $sort1 == 'research_work' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<td width=50>
<A HREF='javascript: sort("eco_status")' class=hilighted>Status</A>
<?php
if ($sort1 == 'eco_status' || $sort2 == 'eco_status') {
$order = $sort1 == 'eco_status' ? $order1 : $order2;
echo '<img src=images\\'.($order == 'DESC' ? 'down' : 'up').'.gif />';
}
?>
</td>
<TD></TD>
</tr>
Here is the javascript function each link calls:
Code:
<script language=javascript>
function sort(sort_by) {
/* this function is used to determine what column(s) to sort by and, for each column,
whether to sort ascending or descending.
*/
//get current sort method
var sort1 = document.getElementById('sort1');
var order1 = document.getElementById('order1');
var sort2 = document.getElementById('sort2');
var order2 = document.getElementById('order2');
//test if we are already sorting by one of these
if (sort1.value == sort_by) {
//if the primary sort matches then change the order
if (order1.value == 'DESC') {
order1.value = 'ASC';
} else {
order1.value = 'DESC';
}
} else if (sort2.value == sort_by) {
//if the secondary sort matches then switch priorities
temp_sort = sort1.value;
temp_order = order1.value;
sort1.value = sort2.value;
order1.value = order2.value;
sort2.value = temp_sort;
order2.value = temp_order;
} else {
//otherwise make the primary sort method secondary and make the new sort primary
sort2.value = sort1.value;
order2.value = order1.value;
sort1.value = sort_by;
order1.value = 'DESC';
}
//submit the sort form
document.frmSort.submit();
}
</script>
And the html form which is at the bottom of the page after the table (again, the PHP just lets me put in the current sort info):
Code:
<FORM name=frmSort action=list_ecos.php method=POST>
<?php
echo "<INPUT type=hidden name=search_string value='$search_string' />
<INPUT type=hidden name=sort1 id=sort1 value='$sort1' />
<INPUT type=hidden name=order1 id=order1 value='$order1' />
<INPUT type=hidden name=sort2 id=sort2 value='$sort2' />
<INPUT type=hidden name=order2 id=order2 value='$order2' />
<INPUT type=hidden name=limit value='$limit' />";
?>
</FORM>
I've tried putting some alert lines for debugging and they show that the gathered values at the begining are correct and then just before the .submit() is called the new values reflect what it should be.
Then when the page loads it still shows the default sorting. I tried throwing in PHP debugging at the begining of the page:
Code:
<?php
foreach ($_POST as $key => $value) {
echo "$key => $value<BR />";
}
?>
And it confirms that the information is sent but it's sent with the default values before javascript ran.
So, can anyone think of a reason that the information would revert before the post information is sent?
Thanks,
David I. Taylor
Network Administrator