menú de selección móvil permanecer en la opción de selección de URL actual


   $(function() {
            var url = $(this).val();
            window.location = url;


  <option value="">Home</option>
  <option value="">Kitchens</option>
  <option value="">Shop Fitouts</option>
  <option value="">Office Fitouts</option>
  <option value="">Gallery</option>
  <option value="">Joinery</option>
  <option value="">Recent Jobs</option>
  <option value="">Contact Us</option>

It works just fine, but once the select option is clicked and new page appears, the select box returns to 'Home' option, rather than current page.

Wondering how to keep this option selected.

preguntado el 12 de febrero de 14 a las 08:02

Have I understood this right? You want to reload the page and the selected value on the new page should be set to what you selected from the previous? -

You will need to add the selected page as the selected value in the relevant php page. E.g. if you select Kitchens from home you will need to set the select in kitchen.php leer <option selected value="">Kitchens</option> -

I am loading my mobile menu from a php include, the same php include throughout all pages so this solution wouldn't be optimal. -

2 Respuestas

Prueba esto:

    var url = window.location.href;
    $('select option[value="'+url+'"]').prop("selected",true);

Respondido 12 Feb 14, 08:02

He's reloading the page. This will not work upon reload - paolo casciello

Since you're reloading the page, it's the code generating the page (in this case the PHP code) that must write the attribute selected al correspondiente <option> etiqueta.

  <option value="">Home</option>
  <option value="" selected>Kitchens</option>

Respondido 12 Feb 14, 08:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.