javascript - Fill dropdown and radio button choice to proceed to right url -
i trying force customers 2 choices on cart.php before can proceed checkout. based on choices customer redirected correct page. not showing want in woocommerce cart page.
html
proceed please fill following steps.<br> country:<br><select id="selectme"> <option value="none">choose country</option> <option value="sweden">sweden</option> <option value="other">other</option> </select> <br><br><br> <div id="sweden" class="group"> <blockquote><font size="4" face="alice">choose payment method</font><hr> <pre> <form name="jump"> <input type=radio name=a value="http://facebook.com">klarna checkout<br> <input type=radio name=a value="http://google.com">paypal<br> <input type=radio name=a value="http://paypal.com">cash on delivery<br> <input type="button" value="proceed checkout" onclick="linkselect(this.form)"> </form> </div> <div id="other" class="group"> <blockquote><font size="4" face="alice">choose payment method</font><hr> <pre> <form name="jump"> <input type=radio name=a value="http://paypal.com">paypal<br> <input type="button" value="proceed checkout" onclick="linkselect(this.form)"> </form> </div>
javascript
$(document).ready(function () { $('.group').hide(); $('#none').show(); $('#selectme').change(function () { $('.group').hide(); $('#'+$(this).val()).show(); }) }); function linkselect(what) { (var i=0; i<3; i++) { if (what.a[i].checked == true) location.href = what.a[i].value; } }
things need at:
- do not have multiple forms unless there no other way around
- wrap html attributes in quotes.
- do not have pre tags. style elements suit ui
take @ below html/js
demo: fiddle
include below jquery in "head" section of page.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
html (restructured)
<select id="selectme"> <option value="none">choose country</option> <option value="sweden">sweden</option> <option value="other">other</option> </select> <div id="wrapper" class="group" style="display:none;"> <blockquote><font size="4" face="alice">choose payment method</font></blockquote><hr> <form name="jump"> <div class="sweden" style="display:none;"> <input type="radio" name="a" value="http://facebook.com" />klarna checkout<br> <input type="radio" name="a" value="http://google.com" />paypal<br> <input type="radio" name="a" value="http://paypal.com" />cash on delivery<br> </div> <div class="other" style="display:none;"> <input type="radio" name="a" value="http://paypal.com"/>paypal<br> </div> <input id="checkout" type="button" value="proceed checkout" /> </form> </div>
js
$(document).ready(function () { var group = $('.group'); $('#selectme').change(function () { $('form[name="jump"] :radio').prop('checked', false); var selected = $(this).val(); group[selected !== 'none'? "show" : "hide"](); group.find('div').hide(); $('.'+selected).show(); }); $('#checkout').bind('click', function() { var selectedval = $('form[name="jump"] :radio:checked').val(); if ( selectedval ) { //alert (selectedval); window.location.href = selectedval; } }); });
Comments
Post a Comment