901 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+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>
649 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
+1 more
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

901 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
Gareth_Gillman says

Thanks CT but doesn’t work either unfortunately

190 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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by