when yousay "checkboxes" do you include the radio buttons... because you have one hardcoded as "checked" there, so it becomes a little meaningless. But anyway, maybe this is a start...
in that case if you are just looking at checkboxes it would make more sense to do this...
Code:
<script>
inps=document.getElementsByTagName("input");
function valBoxes() {
var count=0;
for (var i = 0; i < inps.length; i++) {
if(inps[i].checked&&inps[i].type=="checkbox"){
count++
}
}
if(count==0){
alert("Select a project");
return false;
}
}
</script>
of course if you have other (unrelated) checkboxes you can further refine the test by giving the target cb's a class and checking for className in the function
but it will still let me submit my form without a checkbox being checked. I have attached my entire script for validation:
Code:
<script language="JavaScript" type="text/JavaScript">
function validate() {
//check a field to make sure it has something filled in
inps=document.getElementsByTagName("input");
var count=0;
for (var i = 0; i < inps.length; i++) {
if(inps[i].checked&&inps[i].type=="checkbox"){
count++
}
}
if(count==0){
alert("Select a project");
return false;
}
if(document.stakeholder.f_type_of_stakeholder.value == "0")
{ alert ( "Please select a Type of Stakeholder." ); return false; }
document.stakeholder.f_type_of_stakeholder.focus();
var bus=document.stakeholder.f_type_of_stakeholder.value;
if(bus=="5")
{
var txt=document.stakeholder.f_organ.value;
if(txt=="")
{
alert("Organization Name is required");
return false;
}
return true
}
if(document.stakeholder.f_contact_date.value == "") {
alert("Please select a date.");
document.stakeholder.f_contact_date.focus();
return false;
}
if(document.stakeholder.f_fname.value == "") {
alert("Please enter a First Name.");
document.stakeholder.f_fname.focus();
return false;
}
if(document.stakeholder.f_lname.value == "") {
alert("Please enter a Last Name.");
document.stakeholder.f_lname.focus();
return false;
}
return true;
}
</script>
the ones for first name and last name work if they are blank....
Hey, i got it, I had some other validation script stuff for some other fields and it appears that script was messing this up.....anyway, THANK YOU, your code worked perfect!
Bookmarks