0

I want pass an input data from phtm file to controller. I create a js file and I can get the value of input that I want pass but how I pass this value to controller only with JavaScript (no Jquery).

phtml file:

<button onclick="inputQty(<?php echo $cont ?>)" id="qtyAdd2Cart" type="submit"
                 title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                 class="action tocart primary">
  <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
</button>

JavaScript:

function inputQty(id){
   id = "qty"+id;
   alert(id)
 }

In this moment only do an alert with id, but I can capture the value of input. I only need pass this value to controller.

Thanks.

  • 2
    Can you put some code here with details? – Sohel Rana Dec 29 '16 at 13:17
  • Yes, I edit the post – AndresF Dec 29 '16 at 14:16
  • Do you use in AJAX Or Page submit? – Sohel Rana Dec 29 '16 at 14:59
  • Is a button that call to controller. The module is from magento, I create a module that override their controller and create a costom js to get the input value. The problem is this value pass to controller. The module on the core imagine that use AJAX because I click in the button and load in minicart the product but the page is the same – AndresF Dec 29 '16 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.