jqueryvariablesparametersnavigationwinjs

Passing and retrieving multiple parameters in jquery from one page to another page


I want to pass 4 names using jQuery from one page to another page using jQuery in winRT app. done using one parameter. How to pass multiple parameters and retrieve in 2nd page?

Coding for one parameter.

default.html:

<html>
<head>
<script>
       $(document).ready(function () {
        $(function () {
            $('#navigate12').click(function () {
                var te = $("#text1").val();
                var tea = $("#text2").val();
                 window.location.href = "/page.html?cal=" + te; 
                   });
        });});
</script>
</head>
<body>
 <button id="navigate12">navigate</button>
 <input id="text1" type="text"/>
 <input id="text2" type="text"/>
 <input id="text3" type="text"/>
 <input id="text4" type="text"/>
</body>
</html>

 page.html
<html>
<head>
      <script src="/js/jquery-1.9.1.js"></script>
      <script>
              $(document).ready(function () {                  
                function qs() {
                var qsparam = new Array();
                var query = window.location.search.substring(1);
                var parms = query.split('&');
                for (var i = 0; i < parms.length; i++) {
                    var pos = parms[i].indexOf('=');
                    if (pos > 0)
                    {
                        var key = parms[i].substring(0, pos);
                        var val = parms[i].substring(pos + 1);
                        qsparam[key] = val;
                    }

                }
               var msg = new Windows.UI.Popups.MessageDialog(val);
               msg.showAsync();
             } 
               var splitstr = qs();
                    });
</script>
<title>
</title>
</head>
<body>

</body>
</html>

Solution

  • done using this technique in default.html

    $(function () {
                   $('#navigate12').click(function () {
                    var te = $("#text1").val();
                    var text2 = $("#text2").val();
                    var text3 = $("#text3").val();
                    var text4 = $("#text4").val();
                    window.location.href = "/page.html?cal=" + te + "&text2=" + text2 +
                   "&text3=" + text3 + "&text4=" + text4; <-- this line has changes to include multiple parameters rest is same as in the question
    

    and in page.html

        <script>
                  $(document).ready(function () {                  
                  function qs() {
                    var qsparam = new Array(10);
                    var query = window.location.search.substring(1);
                    var parms = query.split('&');
                   for (var i = 0; i < parms.length; i++) {
                   var pos = parms[i].indexOf('=');
                   if (pos > 0)
                  {
                            var key = parms[i].substring(0, pos);
                            var val = parms[i].substring(pos + 1);
                            qsparam[i] = val;    
                  }                          
                                                           }
                   text1.value = qsparam[0];
                   text2.value = qsparam[1];
                   text3.value = qsparam[2];
                   text4.value = qsparam[3];
    
    
    
                  }
                  var splitstr = qs();
    
    
    
                        });
        </script>
        <title></title>
    </head>
    <body>
       <input id="text1" type="text" />
        <input id="text2" type="text" />
       <input id="text3" type="text" />
        <input id="text4" type="text" />
     </body>
     </html>
    

    we are calling the function qs() using

    var splitstr = qs();

    it splits the parameters and to see the value of different variable u can use text1.value=parms if any doubt u can ask :-)