654 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Provided great contribution to our forums
  • Has been a beta tester for an Envato feature
+4 more
Gareth_Gillman says

Having a nightmare issue with ajax/jquery on an Opencart theme

The following is my ajax/jquery

$('#button-cart').bind('click', function() {
    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: $('input[type=\'text\'], input[type=\'hidden\'], input[type=radio]:checked, input[type=\'checkbox\']:checked, select, textarea'),

I have a radio of items e.g.

<div id="prod-single-right">
    <div class="widget">
        <div id="option-236" class="option">
            <div class="title" />
            <table>
                <tbody>
                    <tr>
                        <td>
                            <label>
                                <input type="radio" value="67" name="option[13]"></input>
                                <span style="width:40%;">
                                    Blue Extra Large
                                </span>
                                <span style="width:20%;" />
                                <span style="width:10%;" />
                            </label>
  </td>
 </tr>

If I select a radio button and select add to cart, I get the error message that it's not been checked but if I do the following jquery, it displays the data from the radio fine

<pre>
$('input[type="radio"]').click(function(){
    if ($(this).is(':checked'))
    {
      alert($(this).val());
    }
  });
</pre>

Am I missing something basis here?</table></div></div></div>
626 posts
  • Has been part of the Envato Community for over 3 years
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
ChapterThemes says

Maybe you should use val() to send it with the data?

data: $('input[type=\'text\'], input[type=\'hidden\'], input[type=radio]:checked.val()

Just a thought – not tested

654 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Provided great contribution to our forums
  • Has been a beta tester for an Envato feature
+4 more
Gareth_Gillman says

Thanks CT but doesn’t work either unfortunately

84 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in Kosovo
+2 more
vuzzu says

Hi there,

did you try data: $(this).parents(‘form’).serialize(),
it will serialize for you whole inputs on the form.

by
by
by
by
by
by