Save option after upgrade

I have a list of people sorted by 2 parameters that I put in select.

How can, when someone selects a parameter, support it if it is updated or changed / returned to the page?

I see some problems on some posts on the Internet, but most of them use jQuery and I don't want to use it.

The code is as follows:

<select name="idactivity_contact[]" id="_activity" multiple="multiple" size="10" style="width:150px;">
    <option disabled="disabled" style="background-color:#dddddd;font-weight:bold;">Shipbroking</option>
    <option value="1">Newbuilding</option>
    <option value="2">Sales and Purchase</option>
    <option value="3">Bulk</option>
</select>

The code is generated in PHP manually, but I will execute the function later

+4
source share
2 answers

One way is to use javascriptand localStorage:

document.getElementById("_activity").onchange = function() {
    localStorage.setItem('selectedtem', document.getElementById("_activity").value);
}

if (localStorage.getItem('item')) {
    document.getElementById("selectedtem").options[localStorage.getItem('selectedtem')].selected = true;
}​

You can also use cookieseither sessionin your side.

+6
source

$_POST [] $_SESSION [].

0

Source: https://habr.com/ru/post/1530199/


All Articles