javascript validation: Did they select a button? any button?

Posted on 2013-10-11
Medium Priority
Last Modified: 2013-10-12
I have 3 radio buttons. I need to have the user select either a trial of the product or one of two subscription options.
see http://ara-usa.org/brizo/

I don't care which button. I don't need the value of the button. I just need to make sure they selected something and, if they didn't, display an message box.
Question by:LyndaPostal
  • 2
  • 2
LVL 58

Expert Comment

ID: 39567459
Just set the first one to selected (or whichever one you want selected by default) then you don't have to worry about one being selected.
So just add selected into your first radio button

Author Comment

ID: 39567551
I understand that ... I would LOVE to do that, but the client (bless their black little heart) wants NOTHING to be assumed. So no pre-selection. But they (of course) want it caught. A polite little message asking the user to please make a selection.

I've been working in vb.net I've not worked in classic asp in a while. And .net validation is drag-n-drop, set some parameters and go (for the most part). I've got two more sites to make changes to by Monday and my head hurts. There has got to be a way to do this.

Please ....
LVL 58

Accepted Solution

Gary earned 2000 total points
ID: 39567561
Add to your FORM tag
onsubmit="return checkradio()"

Add this js function
function checkradio(){
	var radiocheck = false;
	for (var i=0; i < document.form1.selectOption.length; i++){
		if (document.form1.selectOption[i].checked){
			radiocheck = true;
	if (radiocheck ==false){alert("Select an option");return false;}

Open in new window


Author Closing Comment

ID: 39568266
Thank you so much. I knew it would be simple for someone who knows javaScript. I did Google searches, searched within the ee javascript solutions and could find nothing that simply did a quick radio button validation.

I'm grateful.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
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)

586 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