sachin
06-30-2003, 01:37 PM
Hi,
Actually I am reading the url to get name value pairs from html file through a javascript method,based on some conditions ,One of the name,value can exists or not.
for example: in the below url which i have given does not
have "book" as the name in the url.
so i need to check if it is there or not, if it is not there
then i need to pass null value, some-thing like i need
to check for "undefined".
Let me know how can this be achieved.
below is the sample code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
function jsGetUrl()
{
var oArgObj = new Object();
//var sParams = location.search.substring(1);
var sParams = "http://127.0.0.1:8080/aal/view/view.htm?id=091111abcdef0001&toc=y&p=091111abcdef0001/520608.003/TPSEC04.pdf@xml=http://127.0.0.1:8080/vtopic.isapi?action=view&Vdkvgwkey=../../aaa/content/091111abcdef0001/520608.003/TPSEC04.pdf&doctype=xml&collection=vc1&Queryzip=sql"
var sPairs = sParams.split("&");
var sPos, sArgname, sValue;
for (var iCnt = 0; iCnt < sPairs.length; iCnt++)
{
sPos = sPairs[iCnt].indexOf('=');
if (sPos == -1) continue;
sArgname = sPairs[iCnt].substring(0,sPos);
sValue = sPairs[iCnt].substring(sPos+1);
if (sValue.indexOf('@') != -1 )
{
var aTemp = sPairs[iCnt].split("@");
sValue = aTemp[0].substring(sArgname.length + 2);
oArgObj[sArgname] = sValue;
sArgname = "xml" ;
sValue = aTemp[1].substring(sArgname.length + 1);
}
oArgObj[sArgname] = sValue;
}
return oArgObj;
}
var oGetArgs = jsGetUrl();
var utest = oGetArgs.book;
var sBooktxt;
if (typeof utest == "undefined")
sBooktxt = "" ;
else
sBooktxt = oGetArgs.book;
alert("final " + sBooktxt);
//--></SCRIPT>
</body>
</html>
Actually I am reading the url to get name value pairs from html file through a javascript method,based on some conditions ,One of the name,value can exists or not.
for example: in the below url which i have given does not
have "book" as the name in the url.
so i need to check if it is there or not, if it is not there
then i need to pass null value, some-thing like i need
to check for "undefined".
Let me know how can this be achieved.
below is the sample code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
function jsGetUrl()
{
var oArgObj = new Object();
//var sParams = location.search.substring(1);
var sParams = "http://127.0.0.1:8080/aal/view/view.htm?id=091111abcdef0001&toc=y&p=091111abcdef0001/520608.003/TPSEC04.pdf@xml=http://127.0.0.1:8080/vtopic.isapi?action=view&Vdkvgwkey=../../aaa/content/091111abcdef0001/520608.003/TPSEC04.pdf&doctype=xml&collection=vc1&Queryzip=sql"
var sPairs = sParams.split("&");
var sPos, sArgname, sValue;
for (var iCnt = 0; iCnt < sPairs.length; iCnt++)
{
sPos = sPairs[iCnt].indexOf('=');
if (sPos == -1) continue;
sArgname = sPairs[iCnt].substring(0,sPos);
sValue = sPairs[iCnt].substring(sPos+1);
if (sValue.indexOf('@') != -1 )
{
var aTemp = sPairs[iCnt].split("@");
sValue = aTemp[0].substring(sArgname.length + 2);
oArgObj[sArgname] = sValue;
sArgname = "xml" ;
sValue = aTemp[1].substring(sArgname.length + 1);
}
oArgObj[sArgname] = sValue;
}
return oArgObj;
}
var oGetArgs = jsGetUrl();
var utest = oGetArgs.book;
var sBooktxt;
if (typeof utest == "undefined")
sBooktxt = "" ;
else
sBooktxt = oGetArgs.book;
alert("final " + sBooktxt);
//--></SCRIPT>
</body>
</html>