javascript - Multiple option selects to create unique shopping cart SKU -
is there way of inserting string field, whereby string predetermined depending on options selected 2 drop downwards menus?
this combination of 2 drop downwards menus creates unique sku product, , string referred sku inserted input value of item_number variable , passed paypal during checkout.
i utilize illustration of selling tee-shirts. combinations black/small, black/large, white/small, & white/large. , each have unique sku of teeshirt-bs, teeshirt-bl, teeshirt-ws & teeshirt-wl respectively.
here html alternative selects, however, think need javascript insert sku value field.
<input type="hidden" name="on0" value="colour"><b>select colour</b></><br> <select name="os0" > <option value="black">black</option> <option value="white">white</option> </select> <br> <br> <input type="hidden" name="on1" value="size"><b>select size</b></><br> <select name="os1" > <option value="small">small</option> <option value="large">large</option> </select> <!-- sku--> <input type="hidden" name="item_number" value="">
try following:
class="snippet-code-js lang-js prettyprint-override">var sizelist = document.getelementbyid('size'); var colorlist = document.getelementbyid('color'); sizelist.onchange = function() { generatesku(); }; colorlist.onchange = function() { generatesku(); }; function generatesku() { var selectedsize = sizelist.options[sizelist.selectedindex].text; var selectedcolor = colorlist.options[colorlist.selectedindex].text; document.getelementbyid('sku').value = 'teeshirt-' + selectedcolor.charat(0).touppercase() + selectedsize.charat(0).touppercase(); } generatesku();
class="snippet-code-html lang-html prettyprint-override"><input type="hidden" name="on0" value="colour"><b>select colour</b></><br> <select id="color" name="os0" > <option value="black">black</option> <option value="white">white</option> </select> <br> <br> <input type="hidden" name="on1" value="size"><b>select size</b></><br> <select id="size" name="os1" > <option value="small">small</option> <option value="large">large</option> </select> <!-- sku--> <input id="sku" name="item_number" value="">
javascript paypal
No comments:
Post a Comment