Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

no output query - asp form - no error message

Status
Not open for further replies.

micawber

Programmer
Dec 10, 2002
71
GB
hi,
can anyone work out why i can't get an output from the form?
i don't recieve an error message so i'm finding it difficult to work out.
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>
<p>&nbsp;</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="10">
&pound;10</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option1" type="radio" value="20">
&pound;20</div></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="center">
<input name="option1" type="radio" value="30">
&pound;30</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option1" type="radio" value="40">
&pound;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="option2" type="radio" value="Yes">
Yes</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<input name="option2" type="radio" value="No">
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>&nbsp;</p>
</form>
</body>
</html>



// 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.value
stroption2 = document.calc.option2.value

// 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;

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")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="1000";
}
{
if (document.calc.annual.value == "20")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="2000";
}
{
if (document.calc.annual.value == "30")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="3000";
}
{
if (document.calc.annual.value == "40")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="4000";
}
{
if (document.calc.annual.value == "50")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="5000";
}
{
if (document.calc.annual.value == "60")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="6000";
}
{
if (document.calc.annual.value == "70")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="7000";
}
{
if (document.calc.annual.value == "80")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.monthly.value="8000";
}
return true;
}
}
}
}
}
}
}
}

// checkoptions.asp

<%
If Request.Querystring("option1") = "10" AND Request.Querystring("option5") = "No" Then
Response.Write("10")
End If
If Request.Querystring("option1") = "10" AND Request.Querystring("option6") = "Yes" Then
Response.Write("20")
End If
If Request.Querystring("option2") = "20" AND Request.Querystring("option5") = "No" Then
Response.Write("30")
End If
If Request.Querystring("option2") = "20" AND Request.Querystring("option6") = "Yes" Then
Response.Write("40")
End If
If Request.Querystring("option3") = "30" AND Request.Querystring("option5") = "No" Then
Response.Write("50")
End If
If Request.Querystring("option3") = "30" AND Request.Querystring("option6") = "Yes" Then
Response.Write("60")
End If
If Request.Querystring("option4") = "40" AND Request.Querystring("option5") = "No" Then
Response.Write("70")
End If
If Request.Querystring("option4") = "40" AND Request.Querystring("option6") = "Yes" Then
Response.Write("80")
End If
%>
 
That is not really a "form" in the traditional HTML sense because it is not submitted. There is no submit button to send the form element values to the server in an HTTP Request. Nor is the form submitted by browser-side script.

Instead the code above has a regular button that triggers a browser-side javascript function. The function uses an function-level instance of xmlhttp to send an asynchronous HTTP "GET" for an ASP. This happens in the last line of the function so the problem may be something as simple as the function ending and the xmlhttp going out of scope before the HTTP Response comes back from the ASP.

The ASP is very simple and unlikely to cause an error so the most likely location for the problem is the JavaScript. I like to use the FireFox browser for debugging Javascirpt, you can install it alongside IE without worry.



 
thanks sheco.
yes the form isn't complete yet and like you said doesn't have a submit button yet. it will have 'eventually'!
i'm taking it section by section, first trying to get an output from the radio buttons.
any help would be great!
 
Can you clarify what you mean by "trying to get an output from the radio buttons."

As far as I know, radio buttons are used to get the user's input so I'm unclear on your objective.
 
There are a few things you have to revise.

[1] Inside calculate.js and inside function count().

> // Collect FORM fields
> stroption1 = document.calc.option1.value
> stroption2 = document.calc.option2.value
[tt]

// Collect FORM fields
var stroption1 = "";
for (var i=0;i<document.calc.option1.length;i++) {
if (document.calc.option1.checked) {
stroption1=document.calc.option1.value;
break;
}
}
var stroption2 = "";
for (var i=0;i<document.calc.option2.length;i++) {
if (document.calc.option2.checked) {
stroption1=document.calc.option2.value;
break;
}
}
[/tt]
[2] In the checkoptions.asp, the logic seems too clumsy and very accidental (non-generic). You should simplify it. (Besides you have not corrected it after changing the option's names defined in the html page.)
[tt]
<%
dim factor
If Request.Querystring("option2") = "Yes" Then
factor=2
Else
factor=1
End If
If IsNumeric(Request.Querystring("option1")) Then
Response.write cint(Request.Querystring("option1"))*factor
Else
Request.write "some error message"
End If
%>
[/tt]
 
Amendment
This line
>[self][ignore]stroption1=document.calc.option2.value;[/ignore]
should be read like this due to incomplete editing.
[tt]stroption[red]2[/red]=document.calc.option2.value;[/tt]
 
Further notes

[2.1] Upon re-reading the script, note that there is no default select of option2 (or for that matter option1 as well), the above asp assume either "No" or non selected, the factor would be 1. Actually, it seems to be a reasonable assumption. If it is not, script the case of neither "Yes" nor "No".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top