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!

Troubles while catching Parameters on IE...

Status
Not open for further replies.

Ditter

Programmer
Sep 11, 2000
16
0
0
FR
I've wrote a couple of functions to read parameters from the URL string, it works fine on NN but it doesn't works on IE. Why?

The related code is:

function getParameterValue(strParamName)
{

//********************************************************
//*
//* Function: getParameterValue()
//* Parameters: strParamName (String, parameter name)
//* Description: Returns the value of a parameter if it
//* exist, null string ("") otherwise. If
//* the given index is greater than the
//* number of elements, returns null.
//* Returns: String. If no parameter found, returns
//* a Null value.
//*
//********************************************************

var queryString = document.location.search.substring(1);
var start = queryString.indexOf(strParamName);

if(start == -1)
{
return null;
}
else
{
if( queryString.indexOf("&") == -1)
{
return queryString.substring(start + strParamName.length + 1 );
}

if( queryString.indexOf("&") == queryString.lastIndexOf("&") && queryString.indexOf("&") != -1)
{

return queryString.substring(start + strParamName.length + 1, queryString.indexOf("&")-1);
}

if(queryString.indexOf("&") != queryString.lastIndexOf("&"))
{

var strTemp = queryString.substring(start);
return strTemp.substring(strTemp.indexOf("=")+1,strTemp.indexOf("&")-1);

}

}

}



[sig][/sig]
 
This script was posted by Nokios a few days ago. It should work for you.
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();
</script>
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Dear Nick:

Thank you for your help, but I´m still wanderinf why it doesn't works on IE. Usually, is easier to work with IE... isn't it?

Thank you again! [sig][/sig]
 
You're right. It's usually easier to get something to work in IE. In any case, the routine posted by Nokios is more efficient and will run faster. Plus, it,s already debugged! [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top