...

View Full Version : converting check boxes to radio buttons



pkarovsky
10-14-2005, 09:14 PM
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows 1252">
<title>Registration Form</title>
<script language="JavaScript">
<!--
function checkCheckBox(f){
if (f.agree.checked == false )
{
alert('Please read Registration Policies then click box to continue.');
return false;
}else
return true;
}

function formReset()
{
var x=document.forms.regform
x.reset()
}

function noenter() {
return !(window.event && window.event.keyCode == 13); }

function check(level){
document.forms(0).answer.value=level
}

function placeFocus() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
}
}
}

}
//declare variables
var i, coursetotal, disc, contrib, subtotal, level, nitems, level;
regfee = 20;

function Total() {
contrib = 0;
disc = 0;
mfee = 100;
level = 0;
coursetotal = 0;
subtotal = 0;
totaldue = 0;
nitems = 4;
for (i=1; i<nitems+1; i++) {
eval("document.regform.Item" + i + "Total.value = '';");
eval("total=document.regform.Item" + i + "course.value * 1;");
eval("document.regform.Item" + i + "Total.value=Currency(total)");
eval("coursetotal = coursetotal + total;");
eval("coursetotal = coursetotal + level;");
}
document.regform.coursetotal.value = Currency(coursetotal);
if (document.regform.member.checked) disc = -(coursetotal * .10);

<!-- I want to convert these three options to radio buttons but when I do I canít get them to work in the function Total()It works as it is written now.
if (document.regform.apprentice.checked) level = 50;
if (document.regform.journeyman.checked) level = 75;
if (document.regform.mfee.checked) level = 100;
if (document.regform.mfee.checked) disc = -(coursetotal * .10);
-- >
document.regform.disc.value = Currency(disc);
document.regform.regfee.value = Currency(regfee);
document.regform.level.value = Currency(level);
subtotal = coursetotal + disc + regfee + level;
document.regform.subtotal.value = Currency(subtotal);
if (parseFloat(document.regform.contrib.value)) contrib = parseFloat(document.regform.contrib.value);
totaldue = subtotal + contrib + level
document.regform.totaldue.value = Currency(totaldue);
}
function Currency(anynum) {
//returns number as string in $xxx,xxx.xx format.
anynum = "" + eval(anynum) //evaluate (in case an expression sent)
intnum = parseInt(anynum) //isolate integer portion
intnum = Math.abs(intnum)
intstr = ""+intnum
//add comma in thousands place.
if (intnum >= 1000) {
intlen = intstr.length
temp1=parseInt(""+(intnum/1000))
temp2=intstr.substring(intlen-3,intlen)
intstr = temp1+","+temp2

}
decnum = Math.abs(parseFloat(anynum)-parseInt(anynum)) //isolate decimal portion
decnum = decnum * 100 // multiply decimal portion by 100.
decstr = "" + Math.abs(Math.round(decnum))
if (decstr.length>2) {decstr=decstr.substring(0,2)}
while (decstr.length < 2) {decstr="0"+decstr}
retval = intstr + "." + decstr
if (anynum < 0) {
retval="("+retval+")"
}
return "$"+retval
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>

<link href="../Stylesheets/regform.css" rel="stylesheet" type="text/css">
</head>
<body OnLoad="placeFocus()">
<form action="sendmail.asp" method="post" name="regform" id="regform" onsubmit="return checkCheckBox(this)">
<table width="780" align="center" cellspacing="0" bgcolor="#FFA250">

<tr>
<td colspan="3" > I am a current Master-level member of Pratt <input name="member" type="checkbox" onKeyPress="return noenter()" value="YES" onClick="Total()">
</td> </tr>

<tr>
<td colspan="5" I would like to take advantage of the member <a href="../PRIMARY/membership.html" target="_blank">benefits<a> so please begin my annual membership: </td> </tr>

<tr align="left" bgcolor="#FFCD95">
<td colspan="5" valign="middle">
<div align="left">
<input name="apprentice" type="checkbox" id="apprentice" value="$50" onClick="Total();">
Apprentice $50 or
<input name="journeyman" type="checkbox" id="journeyman" value="$75" onClick="Total();">
Journeyman $75
<input name="mfee" type="checkbox" id="mfee" value="$100" onClick="Total();">
Master $100 (entitles you to 10% discount on courses
</div>
</td> </tr>

Lerura
10-17-2005, 01:44 AM
if (document.regform.experience[0].checked) level = 50;
if (document.regform.experience[1].checked) level = 75;
if (document.regform.experience[2].checked) level = 100;
if (document.regform.experience[2].checked) disc = -(coursetotal * .10);


<div align="left">
<input name="experience" type="radio" id="apprentice" value="$50" onClick="Total();">
Apprentice $50 or
<input name="experience" type="radio" id="journeyman" value="$75" onClick="Total();">
Journeyman $75
<input name="experience" type="radio" id="mfee" value="$100" onClick="Total();">
Master $100 (entitles you to 10% discount on courses
</div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum