Check checkbox
Hej eksperter,er der nogen der kan hjælpe mig med at modificere følgende script så det kan checke om en checkbox (<input name="Age" type="checkbox" />) er checket af. På forhånd tak.
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("bestillers_navn", "adresse", "post_nr", "tlf", "email", "town", "Sex", "Age");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Fuldenavn", "Adresse", "Post Nr.", "Telefon nr.", "E-mail adresse", "By", "Sex", "Age");
// dialog message
var alertMsg = "Udfyld venlist disse felte(r):\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
og formen
<form name="formcheck" onsubmit="return formCheck(this);" method="post">
<input name="Age" type="checkbox" />
<input class="button" type="submit" value="Check">
</form>