<?php
$sort=$_REQUEST['sortby'];
echo" $sort ";
?>
<html>
<head>
</head>
<body>
<form method="get" id="thisForm" >
<table border=1>
<tr>
<td>
<a href="" name="say" onclick="javascript: sorting(0)">Day </a>
</td>
<td>
<a href="" name="server" onclick="javascript: sorting(1)">Server </a>
</td>
<td>
<a href="" name="service" onclick="javascript: sorting(2)">Service </a>
</td>
<td>
<a href="" name="count" onclick="javascript: sorting(3)">Count </a>
</td>
</tr>
</table>
<input type="hidden" name="sortby" id="sortby"/>
</form>
</body>
<script type="text/javascript" >
var sortArray=new Array("say","server","service","count");
function sorting( cnt)
{
alert(sortArray[cnt]);
document.getElementById("sortby").value=sortArray[cnt];
}
Based on the Header clicked i am trying to build a sort query but after it is submitted on clicking the “a href” link i am unable to get the hidden field posted data ?
I have changed “a href” to submit buttons then how do you stop the page being submitted if we click the same “sort by” link.
Here is what you’re missing:
<a>behavior (for example, usingreturn false).An updated version of
sorting:You can call it using:
Working example: http://jsbin.com/ukoton/3
Another option is to use the popular library jQuery, which can greatly simplify your code:
Working example: http://jsbin.com/ukoton/4