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!

asp querystring ajax dropdown result

Status
Not open for further replies.

micawber

Programmer
Dec 10, 2002
71
GB
Hi, I would like to be able to get a new result in a new field to display from the outcome of the three dropdown menus.
Can anyone help?
Here is what I have so far...
Many 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>
<div id="ValidationResult">Result</div>
<form name="calc" method="post">
<table width="530" border="0" cellpadding="3">
<tr>
<th width="30%" align="right"><div align="center">start</div></th>
<th align="right"><div align="center">colour</div></th>
<th width="30%" align="right"><div align="center">weekly / fortnightly </div></th>
</tr>
<tr>
<td align="right"><div align="center">
<select name="option1">
<option value=""></option>
<option value="10p">10p</option>
<option value="20p">20p</option>
<option value="30p">30p</option>
<option value="40p">40p</option>
</select>
</div></td>
<td width="40%" align="right"><div align="center">
<select name="option2">
<option value=""></option>
<option value="red">red</option>
<option value="blue">blue</option>
</select>
</div></td>
<td align="right"><div align="center"> </div>
<div align="center">
<select name="option3">
<option value=""></option>
<option value="month">month</option>
<option value="year">year</option>
</select>
</div></td>
</tr>
</table>
<table width="530" border="0" cellpadding="3">
<tr>
<td width="317">&nbsp;</td>
<td width="195"><div align="center">Premium:
<input name="pay" type="text" size="10">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input type="button" onClick="count()" value="Calculate Premium">
<input type="reset" value="Reset">
</div></td>
</tr>
</table>
</form>
</body>
</html>


// CHECKOPTIONS.ASP

<%
If Request.Querystring("option1") = "10p" Then
Response.Write("10p")
End If
If Request.Querystring("option1") = "20p" Then
Response.Write("20p")
End If
If Request.Querystring("option1") = "30p" Then
Response.Write("30p")
End If
If Request.Querystring("option1") = "40p" Then
Response.Write("40p")
End If

If Request.Querystring("option2") = "red" Then
Response.Write("red")
Else
Response.Write("blue")
End If

If Request.Querystring("option3") = "month" Then
Response.Write("month")
Else
Response.Write("year")
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 check(regex,current){

re = new RegExp(regex);
for(i = 0; i < document.forms[0].elements.length; i++) {
elm = document.forms[0].elements;
if (elm.type == 'checkbox') {
if (re.test(elm.name)) {
elm.checked = false;
}
}
}
current.checked = true;
}

function count() {


// Collect FORM fields
stroption1 = document.calc.option1.options[document.calc.option1.selectedIndex].value
stroption2 = document.calc.option2.options[document.calc.option2.selectedIndex].value
stroption3 = document.calc.option3.options[document.calc.option3.selectedIndex].value

// Send/recv
var xmlHttp;

xmlHttp = GetXmlHttpObject();

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
pay("ValidationResult", xmlHttp.responseText);
return xmlHttp.responseText;
}
}
var URL = "checkoptions.asp";
URL = URL + "?option1=" + stroption1;
URL = URL + "&option2=" + stroption2;
URL = URL + "&option3=" + stroption3;

xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
}

function pay(strDiv, strMessage) {
if (strBrowserCode == "IE" || strBrowserCode == "FF" || strBrowserCode == "NN" || strBrowserCode ==

"OP" || strBrowserCode == "SA")
{
document.getElementById(strDiv).innerHTML=strMessage;
document.calc.pay.value=strMessage;
}
return true;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top