field validation for radio buttons

L

Larry Jaques

2nd request for javascript newbie help.

I need to check for empty fields and am currently using this script to
do so. The problem is that it doesn't check radio buttons (or
checkboxes). How would I add that in the simplest way? All she wants
me to check for are empties.

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: wsabstract.com -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements;
if (tempobj.name.substring(0,1)=="x") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(2,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field is completed.");
return false;
}
else
return true;
}
// End -->
</script>

I add an x to the fieldname and strip off both the prefix letters
and the x. EG: name="xdname" is a required deliver-to name which
shows up as "NAME" in the alert.

Is there a simple way to add radio button checking?

<input type=radio name="xstype" value="honolulu"><? echo "$honolulu)";
?> Free Delivery in Honolulu<br>
<input type=radio name="xstype" value="oahu"> <? printf
("%.2f",$oahu"; ?> Oahu Delivery outside Honolulu<br>
<input type=radio name="xstype" value="priorityoi"> <? printf
("%.2f",$priorityoi"; ?> Outer Island USPS Priority Mail<br>
<input type=radio name="xstype" value="priorotym"> <? printf
("%.2f",$prioritym"; ?> Mainland USPS Priority Mail<br>
<input type=radio name="xstype" value="fedex"> <? printf
("%.2f",$fedex"; ?> FedEx 2nd Day Air Delivery
(wrapped to 2 lines each by the newsreader)


The above radio button set is overlooked by this script.
TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top