erme Posted April 4, 2014 Share Posted April 4, 2014 I have 2 radio buttons. <input type="radio" name="toasted" id="toasted_sandwiches" value="Toasted Sandwiches" onclick="handleClick();" /> <input type="radio" name="toasted" id="toasted_paninis" value="Toasted Paninis" onclick="handleClick();" /> I want a function that only adds an event (in this case its spry validation) to what radio button is selected. Currently if the user clicks from one radio to the other, both spry events get called. function handleClick() { if (document.getElementById("toasted_sandwiches").checked == true) { var spry_toasted_sandwiches = new Spry.Widget.ValidationCheckbox("spry_toasted_sandwiches", {minSelections:3, validateOn:["change", "blur"]}); } else if (document.getElementById("toasted_paninis").checked == true) { var spry_paninis = new Spry.Widget.ValidationCheckbox("spry_paninis", {minSelections:3, validateOn:["change", "blur"]}); } } Quote Link to comment Share on other sites More sharing options...
john_c_1984 Posted April 6, 2014 Share Posted April 6, 2014 Can you use event listeners and jQuery? If so then this could work <input type="radio" name="toasted" id="toasted_sandwiches" value="Toasted Sandwiches"/> <input type="radio" name="toasted" id="toasted_paninis" value="Toasted Paninis"/> <script type="text/javascript"> $(document).ready(function(){ $( 'input[type=radio][name=toasted]' ).click(function(){ if( $(this).prop('selected') ){ switch( $(this).attr('id') ){ case 'toasted_sandwiches': var spry_toasted_sandwiches = new Spry.Widget.ValidationCheckbox("spry_toasted_sandwiches", {minSelections:3, validateOn:["change", "blur"]}); break; case 'toasted_sandwiches': var spry_paninis = new Spry.Widget.ValidationCheckbox("spry_paninis", {minSelections:3, validateOn:["change", "blur"]}); break; } } }); }); </script> Quote Link to comment Share on other sites More sharing options...
kicken Posted April 6, 2014 Share Posted April 6, 2014 You should probably be using ValidationRadio not ValidationCheckbox. For one, having a minSelections: 3 constraint on radio buttons doesn't even make sense as the whole point of a radio button is that you can only choose one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.