[英]Keep the dropdown value selected after refresh of page
I'm trying to select value, but when I refresh the page it resets the values. 我正在尝试选择值,但是当我刷新页面时,它将重置值。
<div class="clearfix mb-20">
<div class="col s6 m6 l6">
<label class="form-label"><?= __('Gender') ?></label>
<select class="input" name="filter_gender">
<option value="both" <?= $Schedule->get("filter_gender") == "both" ? "selected" : "" ?>><?= __("Both") ?></option>
<option value="male" <?= $Schedule->get("filter_gender") == "male" ? "selected" : "" ?>><?= __("Male") ?></option>
<option value="female" <?= $Schedule->get("filter_gender") == "female" ? "selected" : "" ?>><?= __("Female") ?></option>
</select>
</div>
Any way to get this fixed? 有什么办法解决这个问题?
filter_gender: $form.find(":input[name='filter_gender']").val(),
How do I add gender here? 如何在这里添加性别?
$Schedule->set("user_id", $AuthUser->get("id"))
->set("account_id", $Account->get("id"))
->set("target", $target)
->set("speed", \Input::post("speed"))
->set("is_active", (bool)\Input::post("is_active"))
->set("daily_pause", $daily_pause)
->set("end_date", $end_date);
Solution 1: When you select something in your form (select option), you change the url and add the parameters. 解决方案1:当您选择表单中的某些内容(选择选项)时,将更改URL并添加参数。 So using 'onChange' event on your form or form element you can change the url and add the param.
因此,在表单或表单元素上使用'onChange'事件,您可以更改url并添加参数。
Example: http://www.example.com?my_select_option=any_value
示例:
http://www.example.com?my_select_option=any_value
: http://www.example.com?my_select_option=any_value
Solution 2: Using cookies, set some cookies with a key 'my_specific_form_filters' and values an object with your selected form elements. 解决方案2:使用cookie,使用键“ my_specific_form_filters”设置一些cookie,并使用选定的表单元素为对象赋值。
Example: {my_select_option: “any_value”}
示例:
{my_select_option: “any_value”}
Solution 3: Same logic as cookies applies for local storage where you can save data based on key value. 解决方案3:与Cookie相同的逻辑适用于本地存储,您可以在其中基于键值保存数据。
Solution 4: Save in PHP session based also on key value and retrieve when needed. 解决方案4:还根据键值保存在PHP会话中,并在需要时进行检索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.