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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP AJAX QUERYSTRING 1

Status
Not open for further replies.

micawber

Programmer
Dec 10, 2002
71
GB
I would like to be able to view/show variables from the querystring sent to checkoptions.asp
Can anyone help - point me in the right direction?
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">validation results will appear here</div>
<form name="calc" method="post">
<table width="258" border="0" cellpadding="3" >
<tr>
<td colspan="2"><h4>calculator</h4></td>
</tr>
<tr>
<th width="50%" align="left">option</th>
<th width="50%" align="right">select</th>
</tr>
<tr>
<td>option 1</td>
<td align="right"><input type="checkbox" name="option1"></td>
</tr>
<tr>
<td>option 2</td>
<td align="right"><input type="checkbox" name="option2"></td>
</tr>
<tr>
<td>option 3</td>
<td align="right"><input type="checkbox" name="option3"></td>
</tr>
<tr>
<td>option 4</td>
<td align="right"><input type="checkbox" name="option4"></td>
</tr>
<tr>
<td><strong>price</strong></td>
<td align="right"><input type="text" name="pay"></td>
</tr>
<tr>
<td align="center"></td>
<td align="right">&nbsp;</td>
</tr>
<tr>
<td align="center"></td>
<td align="right"><input type="button" onClick="count()" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>



// CHECKOPTIONS.ASP



<%
Response.Write(Request.ServerVariables("QUERY_STRING"))
%>




// 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
str_option1 = document.calc.option1.checked
str_option2 = document.calc.option2.checked
str_option3 = document.calc.option3.checked
str_option4 = document.calc.option4.checked

// Send/recv
var xmlHttp;

xmlHttp = GetXmlHttpObject();

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
PopDIV("ValidationResult", xmlHttp.responseText);
return xmlHttp.responseText;
}
}
var URL = "checkoptions.asp";
URL = URL + "?option1=" + str_option1;
URL = URL + "&option2=" + str_option2;
URL = URL + "&option3=" + str_option3;
URL = URL + "&option4=" + str_option4;

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

function PopDIV(strDIV, strMessage) {
if (strBrowserCode == "IE")
{
eval("document.all." + strDIV + ".innerHTML='" + strMessage + "';");
}
if (strBrowserCode == "FF" || strBrowserCode == "NN" || strBrowserCode == "OP" || strBrowserCode == "SA")
{
eval("document.getElementById('" + strDIV + "').innerHTML='" + strMessage + "';");
}
return true;
}
 
Those are read in checkoptions.asp like this.
[tt]
<%
boption1=request.querystring("option1")
boption2=request.querystring("option2")
boption3=request.querystring("option3")
boption4=request.querystring("option4")
%>
[/tt]
 
Many thanks tsuji!!
I have amended the following code, I would like to be able to 'pass' or show a result from CHECKOPTIONS.ASP to the 'pay' field on FORM.ASP depending on the result of the options chosen.
Any help would be fantastic!
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 border="0" cellpadding="3">
<tr>
<th width="50%" align="left">Option</th>
<th width="50%" align="right">Select</th>
</tr>
<tr>
<td>option 1</td>
<td align="right"><input type="checkbox" name="option1" onclick="javascript:check('option',this);"></td>
</tr>
<tr>
<td>option 2</td>
<td align="right"><input type="checkbox" name="option2" onclick="javascript:check('option',this);"></td>
</tr>
<tr>
<td>option 3</td>
<td align="right"><input type="checkbox" name="option3" onclick="javascript:check('option',this);"></td>
</tr>
<tr>
<td>option 4</td>
<td align="right"><input type="checkbox" name="option4" onclick="javascript:check('option',this);"></td>
</tr>
<td>
</td>
<tr>
<td>Price:</td>
<td align="right"><input type="text" name="pay"></td>
</tr>
<tr>
<td align="center"></td>
<td align="right"><input type="button" onClick="count()" value="Calculate">
<input type="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>

// CHECKOPTIONS.ASP

<%
boption1=request.querystring("option1")
If boption1 = "false" Then
Response.Write("nothing1")
Else
Response.Write("result1")
End If
boption2=request.querystring("option2")
If boption2 = "false" Then
Response.Write("nothing2")
Else
Response.Write("result2")
End If
boption3=request.querystring("option3")
If boption3 = "false" Then
Response.Write("nothing3")
Else
Response.Write("result3")
End If
boption4=request.querystring("option4")
If boption4 = "false" Then
Response.Write("nothing4")
Else
Response.Write("result4")
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.checked
stroption2 = document.calc.option2.checked
stroption3 = document.calc.option3.checked
stroption4 = document.calc.option4.checked

// Send/recv
var xmlHttp;

xmlHttp = GetXmlHttpObject();

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
PopDIV("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;

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

function PopDIV(strDIV, strMessage) {
if (strBrowserCode == "IE")
{
eval("document.all." + strDIV + ".innerHTML='" + strMessage + "';");
}
if (strBrowserCode == "FF" || strBrowserCode == "NN" || strBrowserCode == "OP" || strBrowserCode == "SA")
{
eval("document.getElementById('" + strDIV + "').innerHTML='" + strMessage + "';");
}
return true;
}
 
I guess rewrite the PopDiv() will get you 90% to the solution, apart from some formatting.
[tt]
function PopDIV(strDIV, strMessage) {
document.getElementById(srrDiv).innerHTML=strMessage;
document.calc.pay.value=strMessage;
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top