douleijiang8111 2012-07-18 10:22
浏览 38
已采纳

jQuery UI链式选择菜单。 单击按钮时表单重置

I am using a chained select-menu to guide the visitor trough some questions. This works like a charm, however, in the end the user has to click a button to send all values to a PHP-script. This also works without a problem, however, when the page reloads (because the button sends the form to the same page), all fields are hidden again and this is not what i want.

I would like the chained selection menu's to be shown when items in them are "selected" when the page reloads. Using PHP i simply test if a field was selected and add that status to the select-menu. But they remain hidden until you manually select everything again.

I think it's just a minor adjustment in the JS-part. But my limited knowledge of JS leaves me without a solution.

Sources

  • 写回答

1条回答 默认 最新

  • dqc18251 2012-07-18 16:49
    关注

    Since the form submits to itself the values the user chose will be available in either $_GET or $_POST (depending on whether the action of your form is get or post).

    The best approach would then be to use those values to set the selected attribute on the appropriate <option> node using something like this.

    $selectedC1Value = '';
    <? if isset($_POST['c1']) { ?>
        $selectedC1Value = $_POST['c1'];
    <? } ?>
    
    <select name="c1" id="c1" >
        <option value="" <? if ($selectedC1Value == '') { echo 'selected'; } ?>>
            --
        </option>
        <option value="age" <? if ($selectedC1Value == '') { echo 'selected'; } ?>>
            Age
        </option>
        <option value="education" <? if ($selectedC1Value == '') { echo 'selected'; } ?>>
            Education
        </option>
        <!-- etc -->
    </select>
    

    This would have to be repeated for each <select> in your <form>.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?