将变量从函数js传递给其他函数js

Pass variable from function js to other function js

我正在尝试传递并保留 store 的值,以便每次用户选择不同的日期时,store 的值都保持不变。

store and day chart

起初,我在选择商店和日期值时设法显示结果。但是,当我换到不同的日期时,它就没有存储值了。

function changestore(){
      var filterstoregen = document.getElementById("filterstoregen").value;
      return filterstoregen;
      window.location.href='/new-retail/visitorreport?storename_='+filterstoregen;
 }


function changeday(){
      var storename2 = changestore();
      var filterday = document.getElementById("filterday").value;
      window.location.href='/new-retail/visitorreport?storename_='+storename2+'&dayname='+filterday;
 }

如果我想看到不同日期的结果,我需要先重新选择商店价值。这是因为图表变成空白,就好像没有选择存储值一样。

注意写在同一个文件里的函数是visitorreport.php.

希望我提供了足够的信息以获得帮助。提前致谢。

与其从头开始重建 URL,您可以获取页面的当前 URL 并只修改下拉列表中更新的参数。

function changestore(){
      var filterstoregen = document.getElementById("filterstoregen").value;
      let params = (new URL(window.location)).searchParams;
      params.set('storename', filterstoregen);
      window.location.search = params.toString();
 }


function changeday(){
      var filterday = document.getElementById("filterday").value;
      let params = (new URL(window.location)).searchParams;
      params.set('dayname', filterday);
      window.location.search = params.toString();
 }