开发者

How to store and recall the last radio button clicked in a session variable

I'm trying to figure out the best way to display text based on which radio button a user has clicked. I am having trouble using sessions to do this. When I use the following code, only the information related to the radio button that was first clicked is displayed (e.g., if someone clicks on radion button "A," then changes hi开发者_运维知识库s mind and clicks on radio button "B," the session seems to think "A" is still clicked.

Any suggestions?

Here's the HTML:

<div class="radio">
  <label for="choice1">Choice 1</label>
  <input class="selection" id="choice1" type="radio" name="selection"  value="choice1"/>

<div class="radio">
  <label for="choice2">Choice 2</label>
  <input class="selection" id="choice2" type="radio" name="selection"  value="choice2" />
</div>

Here's the PHP code:

if (!isset($_SESSION)) {
    session_start();
$_SESSION['formStarted'] = true;
//...

if(($_SESSION['selection']) == 'choice1'){echo 'Text to be included only if choice 1 was selected.';}


$_SESSION['selection'] = isset($_POST[selection]) ? $_POST[selection] : 'choice1';

OR $_GET or $_REQUEST

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜