Edit on
Codepen.io
Codepen.io
Add product at quantity from select field
x
42
1
<!--
2
Initialize the Store Builder Library
3
-->
4
<script
5
id="fsc-api"
6
src="https://sbl.onfastspring.com/sbl/1.0.2/fastspring-builder.min.js"
7
type="text/javascript"
8
data-storefront="fastspringexamples.test.onfastspring.com/popup-fastspringexamples"
9
>
10
</script>
11
12
<select id="qty">
13
<option value="1">1</option>
14
<option value="2">2</option>
15
<option value="3">3</option>
16
<option value="4">4</option>
17
<option value="5">5</option>
18
</select>
19
20
<button onclick="addQty();">Add to Cart</button>
21
22
<script>
23
function addQty()
24
{
25
var e = document.getElementById("qty");
26
var qty = e.options[e.selectedIndex].value;
27
var s =
28
{
29
//Reset the cart session to remove everything added to the cart previously.
30
'reset':true,
31
//Define the product path(s) and the quantity to add.
32
'products' : [
33
{
34
'path':'phot-io-main-app',
35
'quantity': qty
36
}
37
],
38
'checkout': true
39
}
40
fastspring.builder.push(s);
41
}
42
</script>
1
1
1
1