How to store the value in Session using jQuery?
How to store this value in session?
My grid has 3 pages.. with page size 50 when I change this dropdown list box in first page it's doing perfect. but when I got to second page I am not seeing selected value for this dropdown list boxes?
Is there any way that we can maintain seession for th开发者_C百科is dropdownlist box value to send to the next page to set?
By session, do you mean your server-side session variable? If so, you would need to send a post to a page of your language of choice, parse out the variable, and then on the next page, read the session variable and set the option selection accordingly.
If by session, you mean keeping the same option on the client side, this could easily be accomplished by setting a cookie on the clients machine through javascript and then read it in on the next page, or to send a query string along with the url of the next page.
EDIT
If there is no automatic post, I would recommend setting a cookie when a option is chosen.
Here is some pseudocode you can adapt to work for you: (more on javascript cookies @ w3schools )
<option onclick="setcookie("#id")">
function setCookie(choice){
document.cookie="option=" + choice;
}
next page:
$(document).load(checkCookie());
function getCookie(option)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==option)
{
return unescape(y);
}
}
}
function checkCookie()
{
var option=getCookie("option");
if (option!=null && option!="")
{
$(option).selected();
}
}
There's no way to have jQuery store something in your session context. The session is a server-side concept, and is represented at the client by nothing more than an identifier.
You'll have to have a server action you can POST to, and that action can put parameters sent with the POST into the session.
From the client, you also won't be able to access the contents of the session unless your pages explicitly dump out some sort of map onto the page.
jQuery operates on client side, while session is a server-side construct. You'll need to check with your HTTP server (whatever technology you're using) for it.
If you aren't posting it to the server, you can use cookies for persistent client-side storage. Or, if you're not reloading the page, you can store it in regular javascript variables.
You can use cookies. This cookies library has jQuery bindings to cause form elements to be auto filled based on cookie values, and vice versa.
Otherwise, you need to follow the advice of Konrad Garus, Pointy, and Michael Jasper--go to server side.
Another way is using the Cookie. jQuery have cookie plug-in(http://plugins.jquery.com/project/Cookie). You could store the value in the cookie, and get them in the next page. But, it won't work if user turn off cookie.
精彩评论