Jump to content

Unable to extract value from select tag in the ajax-cart.js file


sarfaraz.r1406

Recommended Posts

Hi,

I want to display all the combinations of a product in the product list page. I am able to retrieve the combinations from the Controllers. In product-list.php I am using this code :-

{foreach from=$combinations key=k item=comb}
    {if $product.id_product == $k}
        <p class="comb_title">{$comb.group_name}</p>
            <select>
	        {foreach from=$comb item=attr}
	            <option class="comb_product" value="{$attr.id_product_attribute}">{$attr.attribute_name} {l s=':'} {convertPrice price=$attr.price}</option>
	        {/foreach}
	    </select>
     {/if}
{/foreach}

And extracting the value of class="comb_product" as 

var idComb=  $(this).parent().parent().parent().parent().find('.comb_product').val();

But whatever value is selected from the drop down, it always take the first value only in the variable idComb. Please help me with this issue.

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for the quick reply.

Can you please tell in detail. I am new to js. These changes I have to do in js file or tpl file? 

 

I searched a bit on google and tried this code.

$(this).parent().parent().parent().parent().find('.comb_product').change(function() {
			                                            $( "select option:selected" ).each(function() {
                                                                      var idComb= $(this).val();
                                                                   });
			     			     });

But this also does not work.

Edited by sarfaraz.r1406 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...