We have a form on our site (ex. T-Shirt) that changes based on which radio button you select. I wrote a JS function that pairs the mobile dropdown and desktop radio buttons. While visually everything works, the add to cart functionality only works on desktop and not on mobile.
When I ran the forms through a diffchecker, what I noticed was the only lines that changed were the price displayed and the value of the <input type="hidden" name="variation_id" class="variation_id">.
Currently the dropdown adds the attr of checked to the corresponding radio button, which works for display purposes, but I'm learned the form doesn't actually care whether or not the radio button is checked.
I'm not sure what the form is looking for. I've tried passing a click() to the radio input and its also label. I even tried manually changing the .variation_id from say 652 to 653. But nothing changed. The form didn't process.
Are there attributes that JS looks for in a radio button that you can't see in the markup?
Here's a form with one option selected:
<div class="av-woo-purchase-button avia-builder-el-16 el_after_av_hr avia-builder-el-last "><p class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>25.00</span></p>
<form class="variations_form cart" method="post" enctype="multipart/form-data" data-product_id="651" data-product_variations="[{"attributes":{"attribute_size":"Extra Large"},"availability_html":"<p class=\"stock in-stock\">In stock<\/p>\n","backorders_allowed":false,"dimensions":"N\/A","dimensions_html":"N\/A","display_price":25,"display_regular_price":25,"image":{"title":"Madcap-VNeckTee-Grid-Retina","caption":"","url":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","alt":"Madcap-VNeckTee-Grid-Retina","src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png","srcset":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png 450w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-300x288.png 300w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-768x736.png 768w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-505x484.png 505w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png 960w","sizes":"(max-width: 450px) 100vw, 450px","full_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","full_src_w":960,"full_src_h":920,"thumb_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-120x120.png","thumb_src_w":120,"thumb_src_h":120,"src_w":450,"src_h":431},"image_id":"5823","is_downloadable":false,"is_in_stock":true,"is_purchasable":true,"is_sold_individually":"no","is_virtual":false,"max_qty":"","min_qty":1,"price_html":"","sku":"","variation_description":"","variation_id":652,"variation_is_active":true,"variation_is_visible":true,"weight":".3 lbs","weight_html":".3 lbs","step":1,"input_value":1},{"attributes":{"attribute_size":"Large"},"availability_html":"<p class=\"stock in-stock\">In stock<\/p>\n","backorders_allowed":false,"dimensions":"N\/A","dimensions_html":"N\/A","display_price":25,"display_regular_price":25,"image":{"title":"Madcap-VNeckTee-Grid-Retina","caption":"","url":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","alt":"Madcap-VNeckTee-Grid-Retina","src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png","srcset":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png 450w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-300x288.png 300w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-768x736.png 768w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-505x484.png 505w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png 960w","sizes":"(max-width: 450px) 100vw, 450px","full_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","full_src_w":960,"full_src_h":920,"thumb_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-120x120.png","thumb_src_w":120,"thumb_src_h":120,"src_w":450,"src_h":431},"image_id":"5823","is_downloadable":false,"is_in_stock":true,"is_purchasable":true,"is_sold_individually":"no","is_virtual":false,"max_qty":"","min_qty":1,"price_html":"","sku":"","variation_description":"","variation_id":653,"variation_is_active":true,"variation_is_visible":true,"weight":".3 lbs","weight_html":".3 lbs","step":1,"input_value":1}]" current-image="5823">
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="size">Size</label></td>
<td class="value">
<div class="desktop-only" id="radio"><div><input type="radio" name="attribute_size" value="Small" id="size_v_Small" disabled="disabled"><label for="size_v_Small">Small</label><input type="hidden" name="radio_variation_id" value="655"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=655&attribute_size=Small"></div><div><input type="radio" name="attribute_size" value="Medium" id="size_v_Medium" disabled="disabled"><label for="size_v_Medium">Medium</label><input type="hidden" name="radio_variation_id" value="654"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=654&attribute_size=Medium"></div><div><input type="radio" name="attribute_size" value="Large" id="size_v_Large" checked="checked"><label for="size_v_Large">Large</label><input type="hidden" name="radio_variation_id" value="653"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=653&attribute_size=Large"></div><div><input type="radio" name="attribute_size" value="Extra Large" id="size_v_Extra Large"><label for="size_v_Extra Large">Extra Large</label><input type="hidden" name="radio_variation_id" value="652"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=652&attribute_size=Extra+Large"></div></div><a class="reset_variations" href="#">Clear</a> </td>
</tr>
</tbody>
<div class="mobile-only" id="drop"><select id="size"><option>Small</option><option>Medium</option><option>Large</option><option>Extra Large</option></select></div></table>
<div class="single_variation_wrap">
<div class="woocommerce-variation single_variation" style="">
<div class="woocommerce-variation-description">
</div>
<div class="woocommerce-variation-price">
</div>
<div class="woocommerce-variation-availability">
<p class="stock in-stock">In stock</p>
</div>
</div><div class="woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-enabled">
<div class="quantity_select" style="float: left;">
<select name="quantity" class="qty" title="Qantity">
<option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div> <button type="submit" class="single_add_to_cart_button button alt">Add to cart</button>
<input type="hidden" name="add-to-cart" value="651">
<input type="hidden" name="product_id" value="651">
<input type="hidden" name="variation_id" class="variation_id" value="653">
</div>
</div>
</form>
</div>
Here's the same form with another option selected:
<div class="av-woo-purchase-button avia-builder-el-16 el_after_av_hr avia-builder-el-last "><p class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>25.00</span></p>
<form class="variations_form cart" method="post" enctype="multipart/form-data" data-product_id="651" data-product_variations="[{"attributes":{"attribute_size":"Extra Large"},"availability_html":"<p class=\"stock in-stock\">In stock<\/p>\n","backorders_allowed":false,"dimensions":"N\/A","dimensions_html":"N\/A","display_price":25,"display_regular_price":25,"image":{"title":"Madcap-VNeckTee-Grid-Retina","caption":"","url":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","alt":"Madcap-VNeckTee-Grid-Retina","src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png","srcset":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png 450w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-300x288.png 300w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-768x736.png 768w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-505x484.png 505w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png 960w","sizes":"(max-width: 450px) 100vw, 450px","full_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","full_src_w":960,"full_src_h":920,"thumb_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-120x120.png","thumb_src_w":120,"thumb_src_h":120,"src_w":450,"src_h":431},"image_id":"5823","is_downloadable":false,"is_in_stock":true,"is_purchasable":true,"is_sold_individually":"no","is_virtual":false,"max_qty":"","min_qty":1,"price_html":"","sku":"","variation_description":"","variation_id":652,"variation_is_active":true,"variation_is_visible":true,"weight":".3 lbs","weight_html":".3 lbs","step":1,"input_value":1},{"attributes":{"attribute_size":"Large"},"availability_html":"<p class=\"stock in-stock\">In stock<\/p>\n","backorders_allowed":false,"dimensions":"N\/A","dimensions_html":"N\/A","display_price":25,"display_regular_price":25,"image":{"title":"Madcap-VNeckTee-Grid-Retina","caption":"","url":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","alt":"Madcap-VNeckTee-Grid-Retina","src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png","srcset":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-450x431.png 450w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-300x288.png 300w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-768x736.png 768w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-505x484.png 505w, https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png 960w","sizes":"(max-width: 450px) 100vw, 450px","full_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina.png","full_src_w":960,"full_src_h":920,"thumb_src":"https:\/\/madcapcoffee.com\/wp-content\/uploads\/2017\/07\/Madcap-VNeckTee-Grid-Retina-120x120.png","thumb_src_w":120,"thumb_src_h":120,"src_w":450,"src_h":431},"image_id":"5823","is_downloadable":false,"is_in_stock":true,"is_purchasable":true,"is_sold_individually":"no","is_virtual":false,"max_qty":"","min_qty":1,"price_html":"","sku":"","variation_description":"","variation_id":653,"variation_is_active":true,"variation_is_visible":true,"weight":".3 lbs","weight_html":".3 lbs","step":1,"input_value":1}]" current-image="5823">
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="size">Size</label></td>
<td class="value">
<div class="desktop-only" id="radio"><div><input type="radio" name="attribute_size" value="Small" id="size_v_Small" disabled="disabled"><label for="size_v_Small">Small</label><input type="hidden" name="radio_variation_id" value="655"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=655&attribute_size=Small"></div><div><input type="radio" name="attribute_size" value="Medium" id="size_v_Medium" disabled="disabled"><label for="size_v_Medium">Medium</label><input type="hidden" name="radio_variation_id" value="654"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=654&attribute_size=Medium"></div><div><input type="radio" name="attribute_size" value="Large" id="size_v_Large" checked="checked"><label for="size_v_Large">Large</label><input type="hidden" name="radio_variation_id" value="653"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=653&attribute_size=Large"></div><div><input type="radio" name="attribute_size" value="Extra Large" id="size_v_Extra Large"><label for="size_v_Extra Large">Extra Large</label><input type="hidden" name="radio_variation_id" value="652"><input type="hidden" class="add-to-cart-url" value="https://madcapcoffee.com/?add-to-cart=651&variation_id=652&attribute_size=Extra+Large"></div></div><a class="reset_variations" href="#" style="visibility: visible; display: inline;">Clear</a> </td>
</tr>
</tbody>
<div class="mobile-only" id="drop"><select id="size"><option>Small</option><option>Medium</option><option>Large</option><option>Extra Large</option></select></div></table>
<div class="single_variation_wrap">
<div class="woocommerce-variation single_variation" style="">
<div class="woocommerce-variation-description">
</div>
<div class="woocommerce-variation-price">
</div>
<div class="woocommerce-variation-availability">
<p class="stock in-stock">In stock</p>
</div>
</div><div class="woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-enabled">
<div class="quantity_select" style="float: left;">
<select name="quantity" class="qty" title="Qantity">
<option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div> <button type="submit" class="single_add_to_cart_button button alt">Add to cart</button>
<input type="hidden" name="add-to-cart" value="651">
<input type="hidden" name="product_id" value="651">
<input type="hidden" name="variation_id" class="variation_id" value="652">
</div>
</div>
</form>
</div>
Because clicking on the radio input whose .val() matches the selected option's .text(), I just passed a .click() from the option to its matching radio button.
I have a form on my site that uses Bootstrap 3. It works just fine in IE, Chrome and Safari but for some reason the drop down option element at the end of the form will not work in Firefox. I have tried on different operating systems. The selected option will not 'stay'in the drop down field. Can anyone give me a clue?
<!--------The signup form------->
<form name="signupform" id="signupform" onsubmit="return false;" class="form-signin">
<div class="form">
<div class="form-group">
<input id="username" type="text" class="form-control" onblur="checkusername()"
onkeyup="restrict('username')" maxlength="16" placeholder="Username">
<br>
<span id="unamestatus"></span>
<br>
<input id="email" type="text" class="form-control" placeholder="Email" onfocus="emptyElement('status')"
onkeyup="restrict('email')" maxlength="88">
<br>
<input id="pass1" type="password" class="form-control" placeholder="Create Password" onfocus="emptyElement('status')"
maxlength="100">
<br>
<input id="pass2" type="password" class="form-control" placeholder="Retype Password" onfocus="emptyElement('status')"
maxlength="100">
<br>
<a href="#" data-toggle="tooltip" data-placement="bottom" title="Choose the type of account you want">
<select id="accounttype" class="form-control" onfocus="emptyElement('status')"></a>
<option value="" disabled selected>
Choose Account Type
</option>
<option value="b">
I am an artist
</option>
<option value="a">
I am looking for artists
</option>
</select>
</br>
<br>
<button id="signupbtn" onclick="signup()" class="btn btn-success pull-right">
Create Account
</button>
<br>
<span id="status" style="color: white"></span>
</form>
<!--------End of form------->
You the opening of a select element nested inside an anchor (a) which is invalid markup.
You also have two missing closing div tags before the end of the form.
Also, disabled is not a valid attribute for an option tag.
Correctly formatting your code makes these errors easier to find
<form name="signupform" id="signupform" onsubmit="return false;" class="form-signin">
<div class="form">
<div class="form-group">
<input id="username" type="text" class="form-control" onblur="checkusername()"
onkeyup="restrict('username')" maxlength="16" placeholder="Username">
<br>
<span id="unamestatus"></span>
<br>
<input id="email" type="text" class="form-control" placeholder="Email" onfocus="emptyElement('status')"
onkeyup="restrict('email')" maxlength="88">
<br>
<input id="pass1" type="password" class="form-control" placeholder="Create Password" onfocus="emptyElement('status')"
maxlength="100">
<br>
<input id="pass2" type="password" class="form-control" placeholder="Retype Password" onfocus="emptyElement('status')"
maxlength="100">
<br>
<a href="#" data-toggle="tooltip" data-placement="bottom" title="Choose the type of account you want">
<select id="accounttype" class="form-control" onfocus="emptyElement('status')">
</a> <!-- ^^ select element inside anchor ^^ -->
<option value="" disabled selected> <!-- <-- disabled should be on select element, not option -->
Choose Account Type
</option>
<option value="b">
I am an artist
</option>
<option value="a">
I am looking for artists
</option>
</select>
</br>
<br>
<button id="signupbtn" onclick="signup()" class="btn btn-success pull-right">
Create Account
</button>
<br>
<span id="status" style="color: white"></span>
</div>
</div>
</form>
Im unsure what the <a> is for but it the cause of the specific problem, changing to below will make it work
<select id="accounttype" class="form-control" onfocus="emptyElement('status')">
<option value="" disabled selected>
Choose Account Type
</option>
<option value="b">
I am an artist
</option>
<option value="a">
I am looking for artists
</option>
</select>