Click to See Complete Forum and Search --> : parse url data into array and display array info in html


havey
04-24-2003, 02:13 PM
I have a url as such:
TotalPointScore.htm?ada=87,(age=8),(edu=16),(occ=14),(gua=10),(reg=5),(cat=16),(lan=8),(ada=10)

Now how can i think that i so far have parsed the URL data into an array of all the entries and their respective values.
this is what i have so far: (how can i access the array to get the desc = with value and display it in the html?)... so in the html it would display ,for example, age is 8

function parseAllEntries(){
var temp = data.split(",");
var dataArr = new Array();
z=0;
for(n=0;n<temp.length;n++){
var str = temp[n];
var desc = str.substring(1,str.indexOf("="));
var value = str.substring(str.indexOf("=")+1,str.length-1);
if(n>0){
dataArr[z] = new Array(desc,value);
z++
}
}
dataArr[0][0]+", "+dataArr[0][1]
}
// End -->

AdamGundry
04-24-2003, 02:21 PM
I think this script offers the sort of functionality you are looking for:
http://www.agbs.co.uk/scripts/get_extract.html

To print the age, for example, include the script then use
document.write('age is ' + age);

Adam

havik
04-24-2003, 02:22 PM
I'm not sure what your intentions are, but it appears that you can't access the URL yet (I'm assuming because I don't see it in your code). The following is how to get the URL:

In IE and NS6:
var curURL = document.location.toString();
In NS:
var curURL = window.location.toString();

then you could treat curURL like a string.

Havik

havey
04-24-2003, 03:11 PM
hmm.. maybe i should back up cause i think id be doing something wrong...

I need to reference the url data, that was obtained via forms. this is an example of what the URL might look like as i post the final form to the TotalPointScore.htm page:
TotalPointScore.htm?ada=84,(age=8),(edu=16),(occ=14),(gua=10),(reg=5),(cat=16),(lan=8),(ada=7)
This aspect: ada=84 is a running tally of the totals which i use to display the total score achieved.

The names will always remain the same, example age, edu,occ..., but the values associated with the names are dynamic. I would like to parse the url and display the values in an HTML table?

havik
04-24-2003, 03:15 PM
Using curURL from above, you could parse the string (using substring) for the names (age, edu, occ, etc... ) and then retrieve the corresponding values.

Havik

havey
04-24-2003, 03:26 PM
its that NN issue,

In IE and NS6:
var curURL = document.location.toString();
In NS:
var curURL = window.location.toString();


what about opera or mozilla or other browers?

Would document.location.toString(); in NN4.6 produce an error or would it just be advoided and could i use window.location as well to pick up any non IE & NS6 users?

havik
04-24-2003, 03:52 PM
As far as I know document.location is supported by:
NS3+, IE4+, Opera, aol, and gecko

Try window.location or window.document.location if I am wrong.

Havik