简体   繁体   中英

problem with jquery for add cart button

hi i have a problem with displaying amount.i have the page called make payment in this page i made three radio buttons, if i click the button that amount must add with addcart like a product.

<form method="post" form name="make_payment_frm" action="module/make-payment-module.php" onsubmit="return show_make_payment_validation();" >

    <form id='theForm'>
    <input type="hidden" name="totalamount" id="totalamount" value="1" />
input type="radio" name="rmr"  id="payment1" value="3" onclick="updatepayment(this.value)" />
input type="radio" name="rmr"  id="payment2" value="5.5" onclick="updatepayment(this.value)"/>
input type="radio" name="rmr"  id="payment4" value="10" onclick="updatepayment(this.value)"/>
div id="finalamount">
/div>

i think that problem is my js script. if i click that button there is no response. how do i solve that problem you guys can give me any idea

$(document).ready(function() {
    $(".cart :radio[name='rmr']").add(".cart :radio[name='rmr']").each(function() {
        $(this).click(function() {
            $(".cart :radio[name='rmr']").add(".cart :radio[name='rmr']").each(function() {
                $(this).attr("checked", false);
            });
            $(this).attr("checked", true);
        });
    });
})
    function updatePayment(val) {
      $("<p/>").html("updatePayment(" + val + ")").appendTo(document.body);
    } 

thanks.have a nice day

I have no idea why you seem to be implementing the selecting and un-selecting of radio buttons in jQuery, surely HTML will handle that correctly for you.

However if you are using jQuery, do away with those onclick attributes since that is the benefit of jQuery and achieve the same result as follows:

$(function() {
    $('.cart :radio[name="rmr"]').change(function() {
        if ($(this).is(':checked'))
            updatePayment(this.value);
    });
});

This will attach a change event to every radio button input with the attribute name="rmr" . Thus when the client clicks a new radio button, the value of two radio buttons will change, and the one that is then selected will call the updatePayment function with its value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM