• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

How do i call add_to_cart jquery function to php for getting the input quantity value

April 11, 2020 by

Questions › How do i call add_to_cart jquery function to php for getting the input quantity value
0
Vote Up
Vote Down
Garmaine asked 4 years ago

So, I am trying to get the quantity of the user input and if it matches the total quantity stock then it will be sold as a wholesale product. But I cannot get the jquery function "add_cart_func('qty')" working. Please help!! Trying for hours. Edit- I have added the declaration of let qty = $("#"+type).val();. I have used "radio" for users to choose if they want to buy wholesale or retail.

<?php 
    if ($this->session->user=='good') 
    {   
        $price = $single['pro_quantity_stock'] == add_cart_func('qty') ? $single["pro_wholesale"] : $single["pro_retail"];  
?>
        <input type="radio" name="tt" value="Wholesale" onclick="doDisplay(this);"/>&nbsp;Buy Wholesale
        <span id="wholesales" style="display:none">&nbsp;&nbsp;&nbsp;&nbsp;
            <?php 
                if ($single['pro_wholesale'] != NULL) 
                { 
            ?>
                    <input name="qty" class ='txtbx' size="10" type="number" id="txtNumber" value="<?php echo $single['pro_quantity_stock'] ?>"  disabled />

            <?php
                }
                else
                {
            ?>
                    <input name="qty" class ='txtbx' size="10" type="number" id="txtNumber" value="0"  disabled />
            <?php
                }
            ?>
        </span>
        <br />

        <input type="radio" name="tt" value="Retail" onclick="doDisplay(this);"/> Buy Retail
        <span id="retails" style="display:none">&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="qty" class ='txtbx1' size="10" type="number" id="txtNumber1" />
        </span>
        <br />

        <a href="#" class="btn btn-info btn-normal" onclick="add_cart_func(<?= $single['id'] ?>, '<?= $single["pro_title"] ?>', '<?= $price ?>')">
            <span class="glyphicon glyphicon-shopping-cart"></span> ADD TO CART
        </a>




<script type="text/javascript">
    function add_cart_func(id, name, price){
        // let qty = $("input[name='qty']").val();
        let qty = $("#"+type).val();
        jQuery.ajax({
            url: '<?= base_url("product/add_to_cart")?>',
            data: {'id':id, 'name':name, 'price': price, 'qty': qty},
            type: 'post',
            dataType: 'html',
            success: function(res){
                let _res = JSON.parse(res);
                $('span.p1.fa-stack.fa-2x.has-badge').attr('data-count', _res['qtys']);
                $('#navbar-cart-lists').html(_res['contents']);
            },
            error: function(err){
                console.log(error);
            }
        });
    }
</script>

<script>
    var type = "txtNumber";
    function doDisplay(radio)
    {
        switch (radio.value)
        {
            case "Wholesale":
                document.getElementById("wholesales").style.display = "inline";
                document.getElementById("retails").style.display = "none";
                type = "txtNumber"; 
                break;

            case "Retail":
                document.getElementById("wholesales").style.display = "none";
                document.getElementById("retails").style.display = "inline";
                type = "txtNumber1"; 
                break;
        }
    }
</script>

Controller

function add_to_cart(){ 
    $this->addToCart($this->input->post('id'), 
                    $this->input->post('name'), 
                    $this->input->post('price'), 
                    $this->input->post('qty'),
                    "product");
}
Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: codeigniter, javascript, jquery, php

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023