Question

I am using opencart and got stuck. What I am doing is sending some variable to ajax. This is my data:

data: $('.product-block input[type=\'text\'], .product-block input[type=\'hidden\'], .product-block input[type=\'radio\']:checked, .product-block input[type=\'checkbox\']:checked, .product-block select, .product-block textarea'),

It is working fine. But what I need to do is to replace the '.product-block' from picking a id from anchor click.

I have my id here

var id = $(this).attr('rel');

But I am unable to build the data source from this link. I am using it like this:

data: $(id + ' input[type=\'text\']', id + ' input[type=\'hidden\']', ... ),

and tested this

data: $(id + ' input[type=\'text\']', + id + ' input[type=\'hidden\']', ... ),

But it is not working. Can someone help me?

Était-ce utile?

La solution

Remove all ".product-block" occurrences and use find() it's simpler:

var id = "#" + $(this).attr('rel');
$(id).find('input[type=\'text\'], input[type=\'hidden\'], input[type=\'radio\']:checked,  input[type=\'checkbox\']:checked, select, textarea');

DOCUMENTATION

Also don't forget to use serialize() to "pull" the data from the form:

data: $(id).find(...).serialize() //removed ;

DOCUMENTATION

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top