How can I preserve the states of checkbox using session?
I tried the following but does not work.
<form name="size">
<input type="checkbox" name="size[]" value="1" <%@selected.include?("1")%> /> 1
<input type="checkbox" name="size[]" value="2" <%@selected.include?("2")%> /> 2
<input type="checkbox" name="size[]" value="3" <%@selected.include?("3")%> /> 3
<input type="submit" value="Filter" /><br></form>
@selected is a instance variable in controller that stores the states of the checkbox using session.
Assuming @selected
is an array, as I can infer from your code example, you can do
<input type="checkbox" name="size[]" value="1" <%= @selected.include?("1") ? "checked" : "" %> /> 1
<input type="checkbox" name="size[]" value="2" <%= @selected.include?("2") ? "checked" : "" %> /> 2
<input type="checkbox" name="size[]" value="3" <%= @selected.include?("3") ? "checked" : "" %> /> 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.