[thelist] JavaScript Validation for Pull-Down Menus and Radio Buttons

Brian Cummiskey Brian at hondaswap.com
Wed Dec 8 09:52:40 CST 2004

Jono wrote:
> I am trying to learn how to do JS form field validation, and have hit a 
> snag.  I have figured out how to validate text fields just fine, but I 
> cannot figure out how to validate pull-down menus, and/or Radio 
> buttons.  

Select menus and radio buttons use an index so to speak since there are 
multiples of them, so you can't just check them like a fill-in.

Here's a couple functions i use.


var theform = window.document.THE_FORM_NAME;
var radioSelected = false;

for (i = 0;  i < theform.fieldname.length;  i++)
	if (theform.fieldname[i].checked)
	radioSelected = true;
if (!radioSelected)
	alert("ERROR:\r\nPlease select the proper fieldname.");
	return (false);


<!--  form:  <select name="abc" id="abc" onchange="checkit(this);"> -->

function checkit(obj) {
	if(obj.options[obj.selectedIndex].value == '') {
		alert("Please select a valid option")

More information about the thelist mailing list