I am using the following code to validate radio buttons. it work fine as long as i have more than one record returned from my recordset that creates the radio buttons dynamically. When I have one record in the recordset, this code fails... any help would be appreciated.

function validateSelect(form){
    var return_var = false
    myOption = -1;
    for (i=0; i<document.process_form.select_record.length; i++) {
        if (document.process_form.select_record[i].checked) {
            myOption = i;
            alert("my Option = " + MyOption);
        }
    }
    if (myOption == -1) {
    alert("You must select a Product Usage record to Update.");
    return false;
    } else {
     return_var = true
     }

}

if there is not an item in the record, then length is not defined.
try:
var _len=document.form.item.length?document.form.item.length:0;

Then if it is 0 you know its not an array.

1000s of Free Javascripts

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.