Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radio button required - JavaScript validation

Tags:

javascript

I know nothing of JavaScript. I had to add a group of two radio buttons to an HTML form with values "yes" and "no". Now I need to make them "required" There are several other required fields in the form and this piece of JavaScript:

    <SCRIPT LANGUAGE="JavaScript">
<!--
reqd_fields = new Array();
reqd_fields[0] = "name";
reqd_fields[1] = "title";
reqd_fields[2] = "company";
reqd_fields[3] = "address";
reqd_fields[4] = "city";
reqd_fields[5] = "state";
reqd_fields[6] = "zip";
reqd_fields[7] = "phone";
reqd_fields[8] = "email";
reqd_fields[9] = "employee";

function validate(form_obj) {
  if (test_required && !test_required(form_obj)) {
    return false;
  }

It was done by someone else, not me. What I did is just added my field to this array, like this:

reqd_fields[10] = "acknowledge";

However it doesn't seem to be working.

Please guide me as I am totally ignorant when it comes to JavaScript.

like image 565
vlevsha Avatar asked Dec 27 '22 20:12

vlevsha


1 Answers

Why don't you just make one selected by default then one will always be selected.

like image 79
locrizak Avatar answered Jan 12 '23 17:01

locrizak