JavaScript radio button validation

Posted on 2013-06-01
Last Modified: 2013-06-01
I am validating some radio buttons on my form. When users forget to check a radio button group an alert window pops up to remind them. The problem is that a separate alert window pops up for each ignored question. How could I modify this script so that only one alert window pops up reminding users that each question has to be answered?
Thanks for your help.
<script type="text/javascript">


function validate_form ( )
	valid = true;

if ( ( document.EvaluationForm.Signature[0].checked == false ) && ( document.EvaluationForm.Signature[1].checked == false ))
alert ( "Did you sign the report?" );
valid = false;

if ( ( document.EvaluationForm.Doors[0].checked == false ) && ( document.EvaluationForm.Doors[1].checked == false ) && ( document.EvaluationForm.Doors[2].checked == false ))
alert ( "Was the door closed?" );
valid = false;

if ( ( document.EvaluationForm.Window[0].checked == false ) && ( document.EvaluationForm.Window[1].checked == false ) && ( document.EvaluationForm.Window[2].checked == false ))
alert ( "Was the window closed?" );
valid = false;

if ( ( document.EvaluationForm.Pool[0].checked == false ) && ( document.EvaluationForm.Pool[1].checked == false ) && ( document.EvaluationForm.Pool[2].checked == false ))
alert ( "Did you clean the Pool?" );
valid = false;

if ( ( document.EvaluationForm.Carrots[0].checked == false ) && ( document.EvaluationForm.Carrots[1].checked == false ) && ( document.EvaluationForm.Carrots[2].checked == false ))
alert ( "Do you like carrots?" );
valid = false;

return valid;



<input type="radio" name="Signature" id="Signature.0" onclick="showHide('Yes','block');showHide('No','none');"> Yes
<input type="radio" name="Signature" id="Signature.1" onclick="showHide('Yes','none');showHide('No','block');"> No

<input type="radio" name="Doors" value="Yes" id="Doors.0" alt="Yes" title="Yes" /> Yes
<input type="radio" name="Doors" value="No" id="Doors.1" alt="No" title="No" /> No
<input type="radio" name="Doors" value="NA" id="Doors.2" alt="N/A" title="NA" /> N/A


Open in new window

Question by:romsom
LVL 58

Assisted Solution

Gary earned 100 total points
ID: 39212839
Declare a blank var at the start e.g. msg=""
For each of your alerts above append the var instead of an alert e.g. msg+="Your message/n"

Then at the end

if (msg!=""){
return valid;
LVL 44

Accepted Solution

Rainer Jeschor earned 400 total points
ID: 39212844
something like this:

Author Closing Comment

ID: 39212848
Thank you very much. RainerJ, I really appreciate your complete solution; I've just realized how cool it looks with my real form.

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now