dqitk20644 2012-09-25 11:24
浏览 35

点击浏览器后退按钮时如何保持无线电选择状态?

I am handling a survey multistep form with many radio sets.

They have some default states

User operates over them to select his preferences.

Now the client wants when hitting either browser back button or the side navigator links (a set of links pointing to previous stages of the survey) to have the radio states the user previously chose.

Here is how the navigator looks like:

<ul>
<li><a href="index.php?site=form1">Step1</a></li>
<li><a href="index.php?site=form2">Step2</a></li>
<li><a href="index.php?site=form3">Step3</a></li>
</ul>

There is only one $_SESSION that collects data throughout the survey.

I know I can load information directly from $_SESSION but I need to replace the default states when the request comes from the navigator links/ back button.

  • 写回答

3条回答 默认 最新

  • duandian8110 2012-09-25 11:26
    关注

    There are two main approaches to this, basically you are saying that the chosen state of the radio's need to be saved between different pages of your form.

    So when you return to a page you were on previously but without submitting, the choices should still be the same.

    There are two key approaches, server side with PHP or client side with Javascript

    PHP

    You can set any link on the website to submit the form and you could save the radio selections, then when you create the form you can check the previously selected value

    This information could be saved in $_SESSION but they'd need to submit the form each time they changed the page (you could change the links to do this)

    Javascript

    You could write some javascript that remembered the content of the selections and stored them in the users browser as a cookie, this could update everytime they clicked a button. When the page loads the javascript would check for cookies (or local storage) and would load the previous options.

    When they finish and submit the form you'd clear the javascript

    Basic example

    $('form input[type=radio]:checked')
    

    Once I have more information I'll flesh out this answer further

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂