Skip to main content
se añadieron 1764 caracteres en el cuerpo
Origen Enlace
Nik020
  • 186
  • 3

Te envío un ejemplo que cree:

https://codepen.io/niko20/pen/eoojxp?editors=1011

function filter(eve) {
   eve.preventDefault();
   const params = {};
   const category = document.getElementById('category');
   const sizeProduct = document.getElementById('size');

   if (category.value != '0') {
      params.category = category.value;
   }
   if (sizeProduct.value != '0') {
      params.size = sizeProduct.value;
   }
   if ( Object.keys(params).length > 0 ) {
      const urlBase = 'http://localhost/tienda-poo/categoria/ver?';
      const paramsQuery = encodeQueryData(params);
      console.log(urlBase + paramsQuery); 
   } else {
      console.log('http://localhost/tienda-poo/categoria/ver');
   }
}

function encodeQueryData(data) {
   const ret = [];
   for (let d in data) {
      ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d])); 
   }
   return ret.join('&');
}
<form>
  <select id="category">
     <option value="0" selected>Sin Categoría</option>
     <option value="1">Pantalon</option>
     <option value="2">Polera</option>
     <option value="3">Zapatilla</option>
     <option value="4">Zapatilla</option>
   </select>
   <select id="size">
      <option value="0" selected>Sin Talla</option>
      <option value="1">Small</option>
      <option value="2">Medium</option>
      <option value="3">Large</option>
      <option value="4">Extra Large</option>
   </select>
   <button onclick="filter(event)">Filtrar</button>
</form>

Saludos

Te envío un ejemplo que cree:

https://codepen.io/niko20/pen/eoojxp?editors=1011

Saludos

Te envío un ejemplo que cree:

https://codepen.io/niko20/pen/eoojxp?editors=1011

function filter(eve) {
   eve.preventDefault();
   const params = {};
   const category = document.getElementById('category');
   const sizeProduct = document.getElementById('size');

   if (category.value != '0') {
      params.category = category.value;
   }
   if (sizeProduct.value != '0') {
      params.size = sizeProduct.value;
   }
   if ( Object.keys(params).length > 0 ) {
      const urlBase = 'http://localhost/tienda-poo/categoria/ver?';
      const paramsQuery = encodeQueryData(params);
      console.log(urlBase + paramsQuery); 
   } else {
      console.log('http://localhost/tienda-poo/categoria/ver');
   }
}

function encodeQueryData(data) {
   const ret = [];
   for (let d in data) {
      ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d])); 
   }
   return ret.join('&');
}
<form>
  <select id="category">
     <option value="0" selected>Sin Categoría</option>
     <option value="1">Pantalon</option>
     <option value="2">Polera</option>
     <option value="3">Zapatilla</option>
     <option value="4">Zapatilla</option>
   </select>
   <select id="size">
      <option value="0" selected>Sin Talla</option>
      <option value="1">Small</option>
      <option value="2">Medium</option>
      <option value="3">Large</option>
      <option value="4">Extra Large</option>
   </select>
   <button onclick="filter(event)">Filtrar</button>
</form>

Saludos

Origen Enlace
Nik020
  • 186
  • 3

Te envío un ejemplo que cree:

https://codepen.io/niko20/pen/eoojxp?editors=1011

Saludos