All,
I posted this in the JavaScript forum earlier today, but I'd post it here too to see if anybody can help....
I am trying to validate a number of mandatory fields on a form. Most of these are text fields, but I also have a couple of radio buttons and one checkbox which can have more than one value ticked. The existing script, which I must admit is not mine, caters for blanks in the mandatory text fields great, but I just cannot get it to process the radio buttons or checkboxes. I've tried adding to the end of the script, but it just seems to ignore it, or more probably, never get there. I've put in debuggin ALERT messages, but just do not have enough knowledge to crack it. I can see I'm going to have to go and buy a book and learn this JS stuff properly rather that knock it up on the fly. Any help that you can give will be greatly appreciated.
Script is:
function checkforblanks()
{
for (var i = 0; i < arguments.length; i += 2)
{
if (!arguments)
{alert("Please enter " + arguments[i+1] + "."return false;}
}
return true;
}
function validate()
{
// Make sure none of the required fields are empty
var isFull = checkforblanks(document.myForm.fname.value, "your first name",
document.myForm.lname.value, "your last name",
document.myForm.addr1.value, "the 1st line of your address",
document.myForm.town.value, "your town",
document.myForm.county.value, "your county",
document.myForm.pcode.value, "your postcode",
document.myForm.phone.value, "your phone number (including std code)",
document.myForm.email.value, "your e-mail address"
if (!isFull)
{return false;}
}
I posted this in the JavaScript forum earlier today, but I'd post it here too to see if anybody can help....
I am trying to validate a number of mandatory fields on a form. Most of these are text fields, but I also have a couple of radio buttons and one checkbox which can have more than one value ticked. The existing script, which I must admit is not mine, caters for blanks in the mandatory text fields great, but I just cannot get it to process the radio buttons or checkboxes. I've tried adding to the end of the script, but it just seems to ignore it, or more probably, never get there. I've put in debuggin ALERT messages, but just do not have enough knowledge to crack it. I can see I'm going to have to go and buy a book and learn this JS stuff properly rather that knock it up on the fly. Any help that you can give will be greatly appreciated.
Script is:
function checkforblanks()
{
for (var i = 0; i < arguments.length; i += 2)
{
if (!arguments)
{alert("Please enter " + arguments[i+1] + "."return false;}
}
return true;
}
function validate()
{
// Make sure none of the required fields are empty
var isFull = checkforblanks(document.myForm.fname.value, "your first name",
document.myForm.lname.value, "your last name",
document.myForm.addr1.value, "the 1st line of your address",
document.myForm.town.value, "your town",
document.myForm.county.value, "your county",
document.myForm.pcode.value, "your postcode",
document.myForm.phone.value, "your phone number (including std code)",
document.myForm.email.value, "your e-mail address"
if (!isFull)
{return false;}
}