How to collect variables from a URL, insert them into an array and dynamically change
How to collect variables from a URL, insert them into an array and dynamically change a href URLs?
I'm not a developer so please be easy on me here! I am familiar with HTML and not bad at taking snippets of code from various sources and cobbling them together. I've been looking around and just can't seem to find exactly what I need. Very close and yet so far.. Please help!
What I want to do is:
1. collect variables from the URL like this (www.myurl.com/index.html?var1=1&var2=2&var3=3 etc. etc..)
2. Take those variables and insert them into an array while stripping out the un-needed parts. I found this code which gets it but prints it on the screen, which I don't need..
var parameters = location.search.substring(1).split("&");
var temp = parameters.split("=");
l = unescape(temp);
temp = parameters.split("=");
c = unescape(temp);
document.getElementById("log").innerHTML = l;
document.getElementById("pass").innerHTML = c;
<p>http://www.myurl.com/</b><span id="log" ></span></p>
3. Dynamically alter a href tags on the fly based on the parameters gathered from the URL.
I found this code which works great to alter the URLs but (a) the variable is gathered from an input form and I need to be able to take them from the URL. (b) I also need several of them (could be like 20) so an array is needed.
<input type="text" id="mySearchBox" /> <a href="myurl.com/index.html?"; onclick="this.href+=+document.getElementById('mySearchBox').value">Enter Parameter</a>
I'm sure this is like elementary school stuff to you out there but I just can't seem to figure it out so your advice is much appreciated!
That way you have one function that can handle multiple <a> tags, doing the same thing for each.
Thank you for your detailed reply with comments! That was very helpful to gather the variables. Now I'm left hanging with getting them into those <a> tags. I hate to request to be spoon fed here but need a little more help to get to the correct syntax for:
1. <a href="www.myurl.com/index.html?"+'foo'>link1</a>
resulting in the a tag hyperlink www.myurl.com/index.html?bar
... or the addition of the <img src="./images/.."> tag so I can link an image to that dynamic URL
2. <iframe src="www.myurl.com/index.html?"+'glomp'></iframe>
resulting in the iframe opening for www.myurl.com/index.html?the%20widget
Again, my apologies for being thick here! Thank you..
One more thing..
To provide context, this is an example of the type of page I am working on
The 2 dynamic objects are:
1. The banner (which will change per breed)
2. The black buttons (all of the URLs are the same. The only thing that changes is the last digits after the "=" (node=x)).
3. The iFrame on the bottom. Same syntax as the 2nd URL
Can you be more specifiic? Where do those numbers (for the node=x, for example) come from? I don's see any numbers in the querystring.
For example, if I choose "collie" in the breeds dropdown, the URL is just http://www.doxietalk.com/breeds/collie.html
No querystring at all there. Where would your numbers for node=x comefrom???
Thank you again for your patience and support!
There are 2 kinds of links. The ones automatically generated by Amazon are as follows. They are all the same except for the the very last digit. By simply changing that node number, I can control the entire page (a tags and iframe tags).
So I can easily hard code the navigation links to end up one one of these pages and there is no need to store that value anywhere.
The second type are to images and links on my own site. I can easily control them by simply changing name of the graphic or html page to match that. So for example a href="www.mysite.com/images/"+xyz.jpg when xyz is entered through the URL like www.mysite.com/thispage.html?banner1=xyz
Once I understand how to generate the syntax, I can keep using this formula anywhere in the site instead of creating static html pages for every breeed as you see now, which is obviously a pain and not a very elegant solution. This is exactly what I want to avoid doing.
Does that make sense?
It all makes sense, but I see no reason to use the querystring to pass tons of numbers along. It would look bad.
Instead, just look at the page URL, pick up the name of the breed, and use that to index into a table that has all the data.
For example, instead of using a URL like
you might use
Thank you. This is a bit over my head but a great idea. I am playing with it now and will get back with some more questions. I really appreciate all the time and effort in patiently responding to me :)
|All times are GMT +1. The time now is 06:22 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.