tags:

views:

99

answers:

3

I want to make the application like below.

First there is a page with four radio buttons. The user clicks on any of the radio buttons but doesn't save and he goes to another page. Then if he comes back to same page with the radio buttons it shows the selected radio button before he goes to another page.

How can I do it by using jQuery and PHP?

+1  A: 

You can either save the value in a database, or in a cookie (with javascript, jquery: settings cookie with jquery

EDIT: As palasso said, you can also use php sessions instead of the cookie, all depends on your need.

For example, the user can change the cookies you created (they are just .txt files) and alter the information within.

In your situation, this dont seem to be a problem (becose the cookie depends on the checkboxes the user clicked).

So, you should go with database storage if:

  1. Need to store the checks for long time;
  2. Need to do complex elaboration on them;

Else, go with cookies/session.

DaNieL
A: 

First of all you have to start session in your php script. Then use ajax request on a radio button click storing the selected value in the session.

stefita
A: 

Sessions and cookies are the easier options. I prefer sessions.

  1. Add a click event to the radio button
  2. When clicked save the selected option into a php session
  3. Each time the page is loaded check if the selected value exists in your session and load it.
pablasso
I prefer session too, but session need php while cookies dont, so cookies ca be created direcly throught javascript without needing a ajax call
DaNieL