hide and show a div from another view by obtaining URL variable value

0

This is the code on the Origin page

<li class=" column list-group-item float-e-margins">
    <a href="~/Questions/Questions?valor=1">
        <span class=" label label-primary">REGISTRO</span>
    </a>
</li>                                                             
<li class=" column  list-group-item float-e-margins">
  <a href="~/Questions/Questions?valor=2">
      <span class="label label-primary">VENTA</span>
  </a>
</li> 

And this is the code of the destination page

    / **      * Function that captures the variables passed by GET        link      * Returns an array of key = > value      * /

<script>
function getGET() {
    // capturamos la url
    var loc = document.location.href;
    // si existe el interrogante
    if (loc.indexOf('?') > 0) {
        // cogemos la parte de la url que hay despues del interrogante
        var getString = loc.split('?')[1];
        // obtenemos un array con cada clave=valor
        var GET = getString.split('&');
        var get = {};




        // recorremos todo el array de valores
        for (var i = 0, l = GET.length; i < l; i++) {
            var tmp = GET[i].split('=');
            get[tmp[0]] = unescape(decodeURI(tmp[1]));
        }
        return get;
    }
}

window.onload = function () {
    //ocultar todos los divs
    $('#registro').hide();
    $('#compra').hide();

    // Cogemos los valores pasados por get
    var valores = getGET();
    if (valores) {
        // hacemos un bucle para pasar por cada indice del array de valores
        for (var index in valores) {
            if (valores[index] == 1) {
                $('#registro').toggle(2000);
                $('#compra').hide();
            }
            else if (valores[index] == 2) {
                $('#registro').hide();
                $('#venta').toggle(2000);
            }

        }
    } 
}
</script>




<body>
 <!--Registro-->
            <div class="card" id="registro">
                <div class="card-header" id="headingOne">
                    <h5 class="mb-0">
                        <button class="btn btn-link " type="button">
                            Registro
                        </button>
                    </h5>
                </div>
                <div class="card-body">
                    <div class=" col-lg-12">
                        <ul class="list-group clear-list m-t">
                            <li class="list-group-item">
                                <strong>RESPUESTAS</strong>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>



            <!--Compra-->
            <div class="card" id="compra">
                <div class="card-header" id="headingThree">
                    <h5 class="mb-0">
                        <button id="" class="btn btn-link">
                            Compra
                        </button>
                    </h5>
                </div>
                <div class="card-body">
                    <div class=" col-lg-12">
                        <ul class="list-group clear-list m-t">
                            <li class="list-group-item fist-item">
                                <strong>RESPUESTA</strong><br />

                            </li>
                            <li class="list-group-item">
                                 RESPUESTA
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
 </body>

help me with the code of link , I modified some things which was according to my need. What I do is that I'm on my page questions and select let's say the option Register then address me to my page where the answers are, but I just want to show me the answers corresponding to what I want, then I send the URL a value of a variable and I receive it in the destination page and with javascript I will obtain the value of that variable through methods which I already add. I hope to give me to understand:).

    
asked by ViA Alondra 02.07.2018 в 14:43
source

0 answers