|
 |
javascript thread: ASP -> JS
Message #1 by Kavanjit Singh <kavanjit.singh@i...> on Wed, 29 Nov 2000 13:07:59 +0530
|
|
//how can i use javascript to read querystring?
var theQueryString= document.location.search
//how can i pass server side values from ASP to Javascript variables?
this is a state object that i use, it outputs a client side javascript
with an array of variables passed from any server object.
use the scripts at the bottom on the client side to add to or modify the
server variables. these values are persisted in the query string between
pages....
check this out:
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
<%//@ Language=JavaScript %>
<%
function state()
{
var
arrArgs=(f_breakQstring(Request.QueryString)!=null)?f_breakQstring(Request.Q
ueryString):new Array(0);
this.arguments=arrArgs;
this.getArg=m_getValuePair;
this.addArg=m_addValuePair;
this.vars2client=outputServerVars;
this.strArrays="";
this.stateXML=""
this._output=_output_state;
}
function _output_state()
{
try
{
this.vars2client()
this.stateXML+="<state>\n<![CDATA[\n\t"
this.stateXML+="<script language='javascript'>\n"
this.stateXML+="\t var serverArray =["
this.stateXML+= this.strArrays +"]\n"
this.stateXML+="function getServerVars(varName)"
this.stateXML+="\n\t {"
this.stateXML+= ""//strArraysValpair //????
this.stateXML+="\t\t for(z=0;z<serverArray.length;z++)\n"
this.stateXML+="\t\t { \n"
this.stateXML+="\t\t\t if(serverArray[z][0]=varName)\n"
this.stateXML+="\t\t\t { \n"
this.stateXML+=" return serverArray[z][1]\n"
this.stateXML+="\t\t\t } \n"
this.stateXML+="\t\t\t else \n"
this.stateXML+="\t\t\t { \n"
this.stateXML+=" return '.::variable not found::.'"
this.stateXML+="\t\t\t } \n"
this.stateXML+="\t\t } \n"
this.stateXML+="\t } \n"
this.stateXML+="</script>\n ]]>\n </state> \n"
return this.stateXML;
}
catch(e)
{
Response.Write(e.description +" .::ERROR _output_state in STATE::.");
Response.End();
}
}
function f_breakQstring(qString)
{
try
{
if(qString!="" && qString!=null && qString!='undefined')
{
var q=unescape(qString)
var pairs = q.split('&')
var result = new Array()
for(i=0;i<pairs.length;i++)
{
result[i]=pairs[i].split('=')// each i in result is a name val pair
array [0]name [1]value
}
return result;
}
else return null;
}
catch(e)
{
Response.Write(e.description +" .::ERROR f_breakQstring in STATE::.");
Response.End();
}
}
function m_getValuePair(strName)
{
try
{
for(z=0;z<this.arguments.length;z++)
{
if(this.arguments[z][0]=strName)
{
return this.arguments[z][1]
}
else
{
return ".::variable not found::.";
}
}
}
catch(e)
{
Response.Write(e.description +" .::ERROR m_getValuePair in STATE::.");
Response.End();
}
}
function m_addValuePair(strName, strValue)
{
try
{
x= new Array(strName, strValue)
this.arguments[this.arguments.length]=x
}
catch(e)
{
Response.Write(e.description +" .::ERROR m_addValuePair in STATE::.");
Response.End();
}
}
function outputServerVars()
{
try
{
for(ppp=0;ppp<this.arguments.length;ppp++)
{
this.strArrays+="['"+ this.arguments[ppp][0] + "','" +
this.arguments[ppp][1]+ "']"
this.strArrays+=((ppp<this.arguments.length-1)?",":"")
}
}
catch(e)
{
Response.Write(e.description +" .::ERROR outputServerVars in STATE::.");
Response.End();
}
}
%>
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
client scripts..........
<script language="javascript">
function changeServerVars(varName,varValue) {
for(q=0;q<serverArray.length;q++)
{
if(serverArray[q][0]=varName)
{
serverArray[q][1]=varValue;
}
else
{
return ".::variable not set::."
}
}
}
function addToServerVars(strName, strValue) {
x= new array(strName, strValue)
serverArray[serverArray.length]=x
}
</script>
good luck these are out of context so if you have any questions feel free to
mail me directly...
-----Original Message-----
From: Kavanjit Singh [mailto:kavanjit.singh@i...]
Sent: Wednesday, November 29, 2000 3:06 PM
To: javascript
Subject: [javascript] ASP -> JS
hi
how can i pass server side values from ASP to Javascript variables?
also how can i use javascript to read querystring?
Ne help is appreciated.
Regards
Ricky
---
NEED TECHNICAL TIPS, TOOLS, AND INSIGHTS? Is FREE okay?
Visit EarthWeb for the latest in IT Management, Software Development,
Web Development, Networking & Communications, and Hardware & Systems.
Click on http://www.earthweb.com for FREE articles, tutorials,
and discussions from the experts.
|
|
 |