Help me to understand.
There is a select , depending on the user's choice in id=contact_method different phone numbers are substituted.
Now you need to implement localStorage so that the user does not have to select the value from select on the next page again.
Using the code below localStorage only works for option , how to fix localStorage work for option and id=contact_method at the same time?
<select id="contactSelect"> <option value="0">Россия</option> <option value="1">Беларусь</option> </select> <p id="contact_method">+7</p> JS 1) Function to replace the phone number depending on the choice in select
document.getElementById("contactSelect").onchange = function() { var value = this.options[this.selectedIndex].value; if(value == '1') { document.getElementById("contact_method").innerHTML = '+375'; } else { document.getElementById("contact_method").innerHTML = '+7'; } } 2) Function for localStorage
document.getElementById("contactSelect").onchange = function() { localStorage.setItem('contactSelect', document.getElementById("contactSelect").value); } if (localStorage.getItem('contactSelect')) { document.getElementById("contactSelect").options[localStorage.getItem('contactSelect')].selected = true; }