E
E
Evgeny Shevtsov2015-11-11 19:53:05
JavaScript
Evgeny Shevtsov, 2015-11-11 19:53:05

How to pass value to js?

For example, there is an input

<input type="text" class="qty-input" name="quantity" size="2" value="1" />

and
<a onclick="addToCart('<?php echo $result['product_id']; ?>', '1');" class="btn btn-cart">Добавить в корзину</a>


Value in input changes, both by +/- and manually entered. So here's how to pass this value to
addToCart('<?php echo $result['product_id']; ?>', '1');
(respectively instead of '1') ?

This is
addToCart('<?php echo $result['product_id']; ?>', document.getElementById('quantity').value);"
I tried, but it takes the initial value of the input, and as I said, its value changes and you need ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor, 2015-11-11
@master2016

Remove this argument "1" altogether. And inside the function, take the value value of this input.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question