Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
137
rated 0 times [  143] [ 6]  / answers: 1 / hits: 27722  / 13 Years ago, tue, may 24, 2011, 12:00:00

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.


More From » javascript

 Answers
26

A link to your page or a sample of your HTML would make this easier, but I'm going to hazard a guess and say that the values in the array match the name attribute of your radio button elements.



If this the case, acknowledge should be the name of both radio buttons, and to make things easier, one should have the attribute checked set to true so there is a default, so you'll get a value either way.



So, something like this:



<input type=radio name=acknowledge value=yes /> Yes <br/>
<input type=radio name=acknowledge value=no checked=true /> No <br/>

[#92071] Monday, May 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleew

Total Points: 70
Total Questions: 87
Total Answers: 117

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;