Forum Moderators: open

Message Too Old, No Replies

Dynamically defining undefined variables in an array.

URL value passing

         

jnscollier

3:51 am on Jun 1, 2006 (gmt 0)

10+ Year Member



I have my website set up where I pass user ids from page to page using an array...

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
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();
// End -->
</script>

HOWEVER... I want to set a default id, in case no other ids are passed.

I have two links on the page and this is how I am calling the array in each...

<script language = "javascript">
<!--
function openPage(PageToLoad)
{
id = unescape(params["id"]);
var url2 = 'http://www.URL.com/';
var urlfinal2 = (url2 + id);

window.open(PageToLoad);
}
//-->
</script>
<a HREF="javascript:openPage('http://www.URL.com/' + id)">LINK HERE</a>

(this one opens up the page in a new window)

and the other link is...
<script language = "javascript">

id = unescape(params["id"]);
var url = 'proveit.html?id=';
var urlfinal = (url + id);

document.write("NEED PROOF!?!".link(urlfinal))
</script>

I reallyyyyy have been trying to figure this out for about 5 days now. IF ANYONE CAN HELP... ID GREATLY! APPRECIATE IT. I know my code isnt the best... but i tried.

****SAMMY******

jshanman

12:58 pm on Jun 1, 2006 (gmt 0)

10+ Year Member



if (typeof params == "undefined") {
params = new Array();
}
if (typeof params["id"] == "undefined") {
params["id"] = 0;//place default id here
}

Is this what your asking? If id is not set, then create it?

- JS