Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to validate radio buttons?
    primarykey
    data
    text
    <p>I created the following form: <a href="http://jsfiddle.net/baumdexterous/GYNSu/1/" rel="nofollow">http://jsfiddle.net/baumdexterous/GYNSu/1/</a></p> <p>I implemented a validation script that works for many of the form elements but for some reason it's not working for the radio buttons so currently a user can submit the form without selecting one of the required radio buttons. </p> <p>How can I enable validation for the radio buttons using this existing script? Thanks so much.</p> <pre><code> &lt;ul&gt; &lt;li class="required"&gt; &lt;label&gt;What is the U.S. Capital? Please select your answer below:&lt;/label&gt; &lt;div class="questionsone"&gt; &lt;input name="questionone" type="radio" value="a"&gt;a) New York&lt;br&gt; &lt;input name="questionone" type="radio" value="b"&gt;b) Washington DC&lt;br&gt; &lt;input name="questionone" type="radio" value="c"&gt;c) Seattle&lt;br&gt; &lt;input name="questionone" type="radio" value="d"&gt;d) Portland&lt;br&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>Update</strong>: I have this JavaScript part that works with the existing validation. Trying to figure out how to add a way that will detect radio buttons:</p> <pre><code> &lt;script&gt; $(function() { var root = $("#wizard").scrollable(); // some variables that we need var api = root.scrollable(), drawer = $("#drawer"); // validation logic is done inside the onBeforeSeek callback api.onBeforeSeek(function(event, i) { // we are going 1 step backwards so no need for validation if (api.getIndex() &lt; i) { // 1. get current page var page = root.find(".page").eq(api.getIndex()), // 2. .. and all required fields inside the page inputs = page.find(".required :input").removeClass("error"), // 3. .. which are empty empty = inputs.filter(function() { return $(this).val().replace(/\s*/g, '') == ''; }); // if there are empty fields, then if (empty.length) { // slide down the drawer drawer.slideDown(function() { // colored flash effect drawer.css("backgroundColor", "#229"); setTimeout(function() { drawer.css("backgroundColor", "#fff"); }, 1000); }); // add a CSS class name "error" for empty &amp; required fields empty.addClass("error"); // cancel seeking of the scrollable by returning false return false; // everything is good } else { // hide the drawer drawer.slideUp(); } } // update status bar $("#status li").removeClass("active").eq(i).addClass("active"); }); // if tab is pressed on the next button seek to next page root.find("button.next").keydown(function(e) { if (e.keyCode == 9) { // seeks to next tab by executing our validation routine api.next(); e.preventDefault(); } }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload