0

OK here is the deal. I have a survey that I am putting up with over 60 questions. I want to make them all mandatory. I really need to know if the group has a value, don't care what it is.

Here is what I have, but it is only giving me the first value.

<function CheckField(myFieldName, myText){
var x=document.getElementById(myFieldName).value;
window.alert(myFieldName + "1: " +x);

. . .. . .

OK so this returns the first value of 5. It does not matter what I select. All I just need to know if they selected something if not I want to mark the question with a different color so the user knows to go back and answer the question.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
RodgerDJr
  • 1
  • 1
  • 2

2 Answers2

0

Option 1: (EASY!)

Having the attribute "checked" set to "true" would make have a default value either way.

<input type="radio" name="option" />Option 1
<input type="radio" name="option" checked="true" />Option 2

You could also use required instead of checked attribute but some browsers don't support it like Safari.

For info on support:

required

checked

Option 2: JSFiddle:

http://jsfiddle.net/FE7sK/2/

jQuery(function () {
    jQuery('#validateOpt').bind('click', checkRadio);
})

function checkRadio() {
    var isChecked = jQuery("input[type=radio]:checked").val();

    var booleanVlaueIsChecked = false;
    if (isChecked) {
        booleanVlaueIsChecked = true;
        $('#form1').submit();
    } else {
        alert("aaa");
    }
}
imbondbaby
  • 6,351
  • 3
  • 21
  • 54
0

You can try HTML5 required:

<label><input type="radio" name="option" required /> Option 1</label>
<label><input type="radio" name="option" /> Option 2</label>

You can use it on one radio (per each name), or on all of them (see HTML5: How to use the "required" attribute with a "radio" input field).

Community
  • 1
  • 1
Oriol
  • 274,082
  • 63
  • 437
  • 513