Click to See Complete Forum and Search --> : array from url them document.write each into html
catchup
07-08-2003, 10:53 AM
Hello everyone:)
I was searching on parsing a url into an array and then writting the array into the html in individual parts, not using a loop. I can across this:
http://www.faqts.com/knowledge_base/view.phtml/aid/969
but i've been trying to not use the loop and document.write only each value, something like so:
document.write (+ args[arg][1])
document.write (+ args[arg][2])
document.write (+ args[arg][3])
etc...
Trying to adapt the script...nothing seems to work.?
thanks
You may be interested in http://www.infinitypages.com/research/querystring.htm
catchup
07-08-2003, 11:27 AM
well i tried to ues it Pyro and created something that constantly crashes my browser, :confused:
<script language="javascript" type="text/javascript">
window.onload = get;
function get(val) {
if (val != "undefined" && val != undefined) {
querystring = window.location.search.substr(1).split(/&/);
for (i=0; i<querystring.length; i++) {
pairs = querystring[i].split(/=/);
key = pairs[0];
if (key == val) {
query = pairs[1];
break;
}
else {
query = "undefined key";
}
}
}
else {
query = window.location.search.substr(1);
}
}
</script>
<head>
<body>
<script>get('edu')</script>
or
<body>
<script>document.write(edu)</script>
Something like this should work:
<script language="javascript" type="text/javascript">
function get(val) {
if (val != "undefined" && val != undefined) {
querystring = window.location.search.substr(1).split(/&/);
for (i=0; i<querystring.length; i++) {
pairs = querystring[i].split(/=/);
key = pairs[0];
if (key == val) {
query = pairs[1];
break;
}
else {
query = "undefined key";
}
}
}
else {
query = window.location.search.substr(1);
}
document.getElementById("value").innerHTML = query;
}
</script>
<head>
<body onload="get('edu');">
<a href="testing.htm?edu=test">reload with querystring</a>
<div id="value"></div>
catchup
07-08-2003, 01:03 PM
please excuse my dumbness, i still a little lost, this is the url:
?cat=10&dog=20&fis=14&liz=10&bir=5&sna=16&par=10&cat=5&fro=5
so i'm trying to alter the code to have:
<div id="cat"></div>
<div id="dog"></div>
<div id="fis"></div>
<div id="liz"></div>
<div id="bir"></div>
there must be an easier way to write the value of the pairs in the url to the html?
catchup
07-08-2003, 01:46 PM
Thanks Pyro with a little persistence it paid off, problem solved, thnks for the help:D
You're welcome... Glad to hear you kept working on it yourself instead of just waiting for someone to give you the solution. Well done... :)