0
down vote
favorite
i want radio buttons remain selected across all pagination. For taht

I have collected the checked value in pagination at the top of page.

But it is not working well.

What is wrong with this code ?

This is how i get selected value of radio button in session

       session_start();
       if(isset($_POST['answer'])) {
        $_SESSION['answer'] = $_POST['answer'];
         }

         <input type="radio"  name="answer" value="yes" <?php if(isset($_SESSION['answer'])=='yes') {echo "checked"; }?> />
<input type="radio"  name="answer" value="no" <?php if(isset($_SESSION['answer'])=='no') {echo "checked"; }?> />
<input type="radio"  name="answer" value="yes1" <?php if(isset($_SESSION['answer'])=='yes1') {echo "checked"; }?> />
<input type="radio"  name="answer" value="yes2" <?php if(isset($_SESSION['answer'])=='yes2') {echo "checked"; }?> />

It gives me error(notice) like answer is undefined index.

SESSION['answer'] may not have a value set yet. I suggest you do something like this:

session_start();

if (isset($_POST['answer']))
    $_SESSION['answer'] = $_POST['answer'];

if (!isset($_SESSION['answer']))
    $_SESSION['answer'] = 'no';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.