Hi,
I have a form using radio buttons. I need to be able to set the form so that it only allows one selection from each column. So, if one radio button is selected and another gets selected the previous is deselected. The output values do not work if I call the radio buttons the same name which would automatically deselect the previous selected.
Below is the working version of the form apart from the required validation on the radio buttons.
Any help would be brilliant!
Thanks.
// FORM.ASP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html>
<head>
<script language="JavaScript" type="text/javascript" src="calculate.js"></script>
</head>
<body>
<form name="calc" method="get">
<div id="ValidationResult" style="visibility: hidden;">Result</div>
<!--<div id="ValidationResult">Result</div>-->
<p> </p>
<table width="608" border="1" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td width="45%" align="center"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><table width="131" height="142" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" height="30" valign="top"><div align="center"><strong>column 1
</strong></div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option1" type="radio" value="1">
£10</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option2" type="radio" value="1">
£20</div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option3" type="radio" value="1">
£30</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option4" type="radio" value="1">
£40</div></td>
</tr>
</table></td>
<td valign="top"><table width="131" height="142" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" height="30" valign="top"><div align="center"><strong>column 2
</strong></div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option5" type="radio" value="2">
Yes</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option6" type="radio" value="2">
No</div></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="55%" align="center"><p><strong>Annual:</strong>
<input name="annual" type="text">
</p>
<p><strong>Monthly:</strong>
<input name="monthly" type="text">
</p></td>
</tr>
</table>
<table width="439" border="0" cellpadding="3">
<tr>
<td width="421"><div align="right">
<input type="button" onClick="count()" value="Calculate">
<input type="reset" value="Reset">
</div></td>
</tr>
</table>
<p> </p>
<DIV></DIV>
</form>
</body>
</html>
// CHECKOPTIONS.ASP
<%
If Request.Querystring("option1") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("10")
End If
If Request.Querystring("option1") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("20")
End If
If Request.Querystring("option2") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("30")
End If
If Request.Querystring("option2") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("40")
End If
If Request.Querystring("option3") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("50")
End If
If Request.Querystring("option3") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("60")
End If
If Request.Querystring("option4") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("70")
End If
If Request.Querystring("option4") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("80")
End If
%>
// CALCULATE.JS
var strAgentString = navigator.userAgent.toLowerCase(); // The agent info from the browser
var strBrowser; // Full browser name
var strBrowserCode; // Brief browser code
var strBrowserVersion; // Browser version
var strOS; // Operating system
var strWorkString; // Work string
if (InAgentString('konqueror'))
{
strBrowser = "Konqueror";
strOS = "Linux";
}
else if (InAgentString('firefox')) {
strBrowser = "Firefox";
strBrowserCode = "FF";
}
else if (InAgentString('icab')) {
strBrowser = "iCab";
strBrowserCode = "IC";
}
else if (InAgentString('msie')) {
strBrowser = "Internet Explorer";
strBrowserCode = "IE";
}
else if (InAgentString('omniweb')) {
strBrowser = "OmniWeb";
strBrowserCode = "OW";
}
else if (InAgentString('opera')) {
strBrowser = "Opera";
strBrowserCode = "OP";
}
else if (InAgentString('safari')) {
strBrowser = "Safari";
strBrowserCode = "SA";
}
else if (InAgentString('webtv')) {
strBrowser = "WebTV";
strBrowser = "WT";
}
else if (!InAgentString('compatible'))
{
strBrowser = "Netscape Navigator";
strBrowserCode = "NN";
strBrowserVersion = strAgentString.charAt(8);
}
else
{
strBrowser = "An unknown browser";
strBrowserCode = "XX";
}
if (!strBrowserVersion) strBrowserVersion = strAgentString.charAt(intPos + strWorkString.length);
if (!strOS)
{
if (InAgentString('linux')) strOS = "Linux";
else if (InAgentString('x11')) strOS = "Unix";
else if (InAgentString('mac')) strOS = "Mac"
else if (InAgentString('win')) strOS = "Windows"
else strOS = "An unknown OS";
}
function InAgentString(string) {
intPos = strAgentString.indexOf(string) + 1;
strWorkString = string;
return intPos;
}
function GetXmlHttpObject() {
var xmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
{
xmlHttp=new XMLHttpRequest()
return xmlHttp
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{
var strName="Msxml2.xmlHttp"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.xmlHttp"
}
try
{
xmlHttp=new ActiveXObject(strName)
return xmlHttp
}
catch(e)
{
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
xmlHttp=new XMLHttpRequest()
return xmlHttp
}
}
function count() {
// Collect FORM fields
stroption1 = document.calc.option1.checked
stroption2 = document.calc.option2.checked
stroption3 = document.calc.option3.checked
stroption4 = document.calc.option4.checked
stroption5 = document.calc.option5.checked
stroption6 = document.calc.option6.checked
// Send/recv
var xmlHttp;
xmlHttp = GetXmlHttpObject();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
annual("ValidationResult", xmlHttp.responseText);
monthly("ValidationResult", xmlHttp.responseText);
return xmlHttp.responseText;
}
}
var URL = "checkoptions.asp";
URL = URL + "?option1=" + stroption1;
URL = URL + "&option2=" + stroption2;
URL = URL + "&option3=" + stroption3;
URL = URL + "&option4=" + stroption4;
URL = URL + "&option5=" + stroption5;
URL = URL + "&option6=" + stroption6;
xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
}
function annual(strDiv, strMessage) {
if (strBrowserCode == "IE" || strBrowserCode == "FF" || strBrowserCode == "NN" || strBrowserCode ==
"OP" || strBrowserCode == "SA")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.annual.value=strMessage;
}
return true;
}
function monthly(strDiv, strMessage) {
if (document.calc.annual.value == "10") <!-- 100 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="1000";
}
{
if (document.calc.annual.value == "20") <!-- 100 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="2000";
}
{
if (document.calc.annual.value == "30") <!-- 200 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="3000";
}
{
if (document.calc.annual.value == "40") <!-- 200 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="4000";
}
{
if (document.calc.annual.value == "50") <!-- 300 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="5000";
}
{
if (document.calc.annual.value == "60") <!-- 300 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="6000";
}
{
if (document.calc.annual.value == "70") <!-- 400 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="7000";
}
{
if (document.calc.annual.value == "80") <!-- 400 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="8000";
}
return true;
}
}
}
}
}
}
}
}
I have a form using radio buttons. I need to be able to set the form so that it only allows one selection from each column. So, if one radio button is selected and another gets selected the previous is deselected. The output values do not work if I call the radio buttons the same name which would automatically deselect the previous selected.
Below is the working version of the form apart from the required validation on the radio buttons.
Any help would be brilliant!
Thanks.
// FORM.ASP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html>
<head>
<script language="JavaScript" type="text/javascript" src="calculate.js"></script>
</head>
<body>
<form name="calc" method="get">
<div id="ValidationResult" style="visibility: hidden;">Result</div>
<!--<div id="ValidationResult">Result</div>-->
<p> </p>
<table width="608" border="1" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td width="45%" align="center"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><table width="131" height="142" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" height="30" valign="top"><div align="center"><strong>column 1
</strong></div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option1" type="radio" value="1">
£10</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option2" type="radio" value="1">
£20</div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option3" type="radio" value="1">
£30</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option4" type="radio" value="1">
£40</div></td>
</tr>
</table></td>
<td valign="top"><table width="131" height="142" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" height="30" valign="top"><div align="center"><strong>column 2
</strong></div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option5" type="radio" value="2">
Yes</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option6" type="radio" value="2">
No</div></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="55%" align="center"><p><strong>Annual:</strong>
<input name="annual" type="text">
</p>
<p><strong>Monthly:</strong>
<input name="monthly" type="text">
</p></td>
</tr>
</table>
<table width="439" border="0" cellpadding="3">
<tr>
<td width="421"><div align="right">
<input type="button" onClick="count()" value="Calculate">
<input type="reset" value="Reset">
</div></td>
</tr>
</table>
<p> </p>
<DIV></DIV>
</form>
</body>
</html>
// CHECKOPTIONS.ASP
<%
If Request.Querystring("option1") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("10")
End If
If Request.Querystring("option1") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("20")
End If
If Request.Querystring("option2") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("30")
End If
If Request.Querystring("option2") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("40")
End If
If Request.Querystring("option3") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("50")
End If
If Request.Querystring("option3") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("60")
End If
If Request.Querystring("option4") = "true" AND Request.Querystring("option5") = "true" Then
Response.Write("70")
End If
If Request.Querystring("option4") = "true" AND Request.Querystring("option6") = "true" Then
Response.Write("80")
End If
%>
// CALCULATE.JS
var strAgentString = navigator.userAgent.toLowerCase(); // The agent info from the browser
var strBrowser; // Full browser name
var strBrowserCode; // Brief browser code
var strBrowserVersion; // Browser version
var strOS; // Operating system
var strWorkString; // Work string
if (InAgentString('konqueror'))
{
strBrowser = "Konqueror";
strOS = "Linux";
}
else if (InAgentString('firefox')) {
strBrowser = "Firefox";
strBrowserCode = "FF";
}
else if (InAgentString('icab')) {
strBrowser = "iCab";
strBrowserCode = "IC";
}
else if (InAgentString('msie')) {
strBrowser = "Internet Explorer";
strBrowserCode = "IE";
}
else if (InAgentString('omniweb')) {
strBrowser = "OmniWeb";
strBrowserCode = "OW";
}
else if (InAgentString('opera')) {
strBrowser = "Opera";
strBrowserCode = "OP";
}
else if (InAgentString('safari')) {
strBrowser = "Safari";
strBrowserCode = "SA";
}
else if (InAgentString('webtv')) {
strBrowser = "WebTV";
strBrowser = "WT";
}
else if (!InAgentString('compatible'))
{
strBrowser = "Netscape Navigator";
strBrowserCode = "NN";
strBrowserVersion = strAgentString.charAt(8);
}
else
{
strBrowser = "An unknown browser";
strBrowserCode = "XX";
}
if (!strBrowserVersion) strBrowserVersion = strAgentString.charAt(intPos + strWorkString.length);
if (!strOS)
{
if (InAgentString('linux')) strOS = "Linux";
else if (InAgentString('x11')) strOS = "Unix";
else if (InAgentString('mac')) strOS = "Mac"
else if (InAgentString('win')) strOS = "Windows"
else strOS = "An unknown OS";
}
function InAgentString(string) {
intPos = strAgentString.indexOf(string) + 1;
strWorkString = string;
return intPos;
}
function GetXmlHttpObject() {
var xmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
{
xmlHttp=new XMLHttpRequest()
return xmlHttp
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{
var strName="Msxml2.xmlHttp"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.xmlHttp"
}
try
{
xmlHttp=new ActiveXObject(strName)
return xmlHttp
}
catch(e)
{
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
xmlHttp=new XMLHttpRequest()
return xmlHttp
}
}
function count() {
// Collect FORM fields
stroption1 = document.calc.option1.checked
stroption2 = document.calc.option2.checked
stroption3 = document.calc.option3.checked
stroption4 = document.calc.option4.checked
stroption5 = document.calc.option5.checked
stroption6 = document.calc.option6.checked
// Send/recv
var xmlHttp;
xmlHttp = GetXmlHttpObject();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
annual("ValidationResult", xmlHttp.responseText);
monthly("ValidationResult", xmlHttp.responseText);
return xmlHttp.responseText;
}
}
var URL = "checkoptions.asp";
URL = URL + "?option1=" + stroption1;
URL = URL + "&option2=" + stroption2;
URL = URL + "&option3=" + stroption3;
URL = URL + "&option4=" + stroption4;
URL = URL + "&option5=" + stroption5;
URL = URL + "&option6=" + stroption6;
xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
}
function annual(strDiv, strMessage) {
if (strBrowserCode == "IE" || strBrowserCode == "FF" || strBrowserCode == "NN" || strBrowserCode ==
"OP" || strBrowserCode == "SA")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.annual.value=strMessage;
}
return true;
}
function monthly(strDiv, strMessage) {
if (document.calc.annual.value == "10") <!-- 100 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="1000";
}
{
if (document.calc.annual.value == "20") <!-- 100 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="2000";
}
{
if (document.calc.annual.value == "30") <!-- 200 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="3000";
}
{
if (document.calc.annual.value == "40") <!-- 200 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="4000";
}
{
if (document.calc.annual.value == "50") <!-- 300 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="5000";
}
{
if (document.calc.annual.value == "60") <!-- 300 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="6000";
}
{
if (document.calc.annual.value == "70") <!-- 400 Excluded -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="7000";
}
{
if (document.calc.annual.value == "80") <!-- 400 Included -->
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="8000";
}
return true;
}
}
}
}
}
}
}
}