Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
how to add string in dynamic array

Here i got only id how can I modify to get (37398351478977: 1 ,42110385783015:1) string so i can add this in ajax for add to cart

 var values=[];

    $(".ex_product_select").change(function(){
    if($(this).is(":checked"))
      values.push($(this).val());
    else{
      var x = values.indexOf($(this).val());
      values.splice(x,1) ;
    }
    $(".hide_extra_variant").text(values);
    });
 $(document).on("click",".add",function(){ 
   jQuery.post('/cart/update.js', {  updates: {  values } });
  });
<script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>   

 Product1 : <input type="checkbox" class="ex_product_select" style="display:inline-block;" name="exselect" value="37398331392193">
        Product2 : <input type="checkbox" class="ex_product_select" style="display:inline-block;" name="exselect" value="37398351478977">
        Product3 : <input type="checkbox" class="ex_product_select" style="display:inline-block;" name="exselect" value="42110385783015">

<button class="add" value="add_to_cart">Add To Cart</button>

     <p class="hide_extra_variant"></p>

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Do you want this result?

var values=[];

    $(".ex_product_select").change(function(){
    if($(this).is(":checked"))
      values.push({key:values.length+1,value:$(this).val()});
    else{
      var x = values.findIndex(x => x.value == $(this).val());
      values.splice(x,1) ;
    }
    
    console.clear();
    
    console.log(values)
    
    let allValues = "(" + values.map(x => x.value + ":1").join() + ")";
    
    $(".hide_extra_variant").text(allValues);
    });
 $(document).on("click",".add",function(){ 
   jQuery.post('/cart/update.js', {  updates: {  values } });
  });
<script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>   

 Product1 : <input type="checkbox" class="ex_product_select" style="display:inline-block;" name="exselect" value="37398331392193">
        Product2 : <input type="checkbox" class="ex_product_select" style="display:inline-block;" name="exselect" value="37398351478977">
        Product3 : <input type="checkbox" class="ex_product_select" style="display:inline-block;" name="exselect" value="42110385783015">

<button class="add" value="add_to_cart">Add To Cart</button>

     <p class="hide_extra_variant"></p>

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda