Cookies available:

_ym_uid = 1501572828150021607; _ym_isad = 2; value = 11; _ga = GA1.2.889728148.1501572828; _gid = GA1.2.353711974.1501572828; _gat = 1; _ym_visorc_45462804 = w

How do I get the value 11 from value=11; (cookies can change places, 11 can also change from 0 to 99)?

My code was:

 <input type="number" id="skidka" maxlength="2" min="1" max="99" style="width: 50px;" value="0" onchange="fun3()"> <script type="text/javascript"> window.onload = function () { if (document.cookie.length != 0) { var nameValueArray = document.cookie.split("="); value = nameValueArray[1]; document.getElementById("skidka").value = nameValueArray[1]; } } function fun3() { var val = document.getElementById("skidka").value; if (val != 0 ) { value = document.getElementById("skidka").value; document.cookie = "value=" + val + ";expires=Fri, 5 Aug 2017 01:00:00 UTC;"; } } </script> 

It stopped working after connecting the metrics counters, as there were more cookies and it turns out that I’m not taking the right cookie right.

2 answers 2

At the expense of the correctness of the decision is not sure, but you can pull out the value like this:

 var s = '_ym_uid=1501572828150021607; _ym_isad=2; value=11; _ga=GA1.2.889728148.1501572828; _gid=GA1.2.353711974.1501572828; _gat=1; _ym_visorc_45462804=w'; var value = s.split('value=')[1].split(';')[0]; 

    I tried, your code works

     <input type="number" id="skidka" maxlength="2" min="1" max="99" style="width: 50px;" value="0" onchange="fun3()"> <script type="text/javascript"> window.onload = function () { if (document.cookie.length != 0) { var nameValueArray = document.cookie; document.getElementById("skidka").value = document.cookie.split('value=')[1].split(';')[0]; } } function fun3() { var val = document.getElementById("skidka").value; if (val != 0 ) { value = document.getElementById("skidka").value; document.cookie = "value=" + val; } } </script>