1

I have this code:

<script type="text/javascript" language="javascript">
function Get_QS_Values() {
    var arr = new Array();
    var qs = location.search.substring(1);
    var Qs_Value = new Array();
    var str = "";

    arr = qs.split('&');

    for (i = 0; i < arr.length; i++) {
        Qs_Value = arr[i].split('=');
        str += '' + Qs_Value[1] + '<br />';
        var test = str;
    }
    document.getElementById("Querystring").innerHTML = str;
}
</script>
<body onload="Get_QS_Values();">
<div id="Querystring">
</div>
<script type="text/javascript" language="javascript">
document.write(test);
</script>
</body>

How should i do for save value in a variable soo i can write in on page?

Thanks

Richard Dalton
  • 35,513
  • 6
  • 73
  • 91
Andreas
  • 121
  • 2
  • 4
  • 10

1 Answers1

0

A common use for a a function is to return value, redefine it like this

function Get_QS_Values() {
   var qs = location.search.substring(1);
   var arr = qs.split('&');
   var Qs_Value;
   var str = "";

   for (i = 0; i < arr.length; i++) {
      Qs_Value = arr[i].split('=');
      str += '' + Qs_Value[1] + '<br />';
   }

   return str
}

Then you can call it like this outside of the function:

var test = Get_QS_Values();
document.getElementById("Querystring").innerHTML = test;
Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136