0

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.

2
Contributors
1
Reply
12
Views
3 Years
Discussion Span
Last Post by pritaeas
0

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';

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.