Здравствуйте!
Нужен совет.
Есть select с option
<select name="select" onchange="fn()">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
И js
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
))
return matches ? decodeURIComponent(matches[1]) : undefined
}
function setCookie(name, value, props) {
props = props || {}
var exp = props.expires
if (typeof exp == "number" && exp) {
var d = new Date()
d.setTime(d.getTime() + exp*3153600000)
exp = props.expires = d
}
if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }
value = encodeURIComponent(value)
var updatedCookie = name + "=" + value
for(var propName in props){
updatedCookie += "; " + propName
var propValue = props[propName]
if(propValue !== true){ updatedCookie += "=" + propValue }
}
document.cookie = updatedCookie
}
function fn(){
var elem= document.getElementsByName('select')[0]
var currentOptionIndex= elem.selectedIndex;
setCookie('OptionIndex', currentOptionIndex);
}
window.onload=function(){
var elem= document.getElementsByName('select')[0];
elem.selectedIndex=getCookie('OptionIndex') || 1;
}
Не понял как мне применить еще для одного select и option, js выше.