Forum Moderators: open
Any and all advice is welcome. I am trying to solve the problem of how to dynamically change a link based on a users click. Quite simply, i am trying to implement commission junctions shopper ID function in my site. Currently, i copy, paste, and edit the identifying portion of the link by hand. This gets pretty tedious after doing the same thing 20 or 30 times.
Specifically, this is what i need to do...i am told it can be done without a database, and with a simple javascript...
Home page links:
A
B
C
Clicking on "A" will bring a user to a new page. I am seeking the way to assign a value to "A" (maybe site 001), and write that value to the following location in the linked page...(where it says "APPEND INFO HERE")
<a href="http://www.qksrv.net/click-****-xxxx?SID=APPEND INFO HERE" target="_blank" >Link</a>
<img src="http://www.qksrv.net/image-xxx-xxx” width="1" height="1" border="0"><br>
If a user clicks on "b" or "c", the same page would be loaded, except that the?SID= field would reflect whatever value I assign to "b" and "c"
Thanks
---------- Main document ------------
<HTML>
<Head>
<Script Language=JavaScript>
function nextPage(link){
window.open("newPage.html",link);
window.opener = "";
window.close();
}
</Script>
</Head>
<Body>
<center>
<a href=javascript:nextPage('A')> A Link </a>
<br><br>
<a href=javascript:nextPage('B')> B Link </a>
<br><br>
<a href=javascript:nextPage('C')> C Link </a>
</center>
</Body>
</HTML>
------------newPage.html-----------
<HTML>
<Head>
<Script Language=JavaScript>
var currLink = window.name;
linkURL = new Array();
linkURL[0] = "/A_Link.html"
linkURL[1] = "/B_link.html"
linkURL[2] = "/C_Link.html"
if (currLink == 'A'){currLink = linkURL[0]}
if (currLink == 'B'){currLink = linkURL[1]}
if (currLink == 'C'){currLink = linkURL[2]}
var linkStr = "<a href=http://www.qksrv.net/click"+currLink+" target='_blank'>Link</a>"
</Script>
</Head>
<Body>
<Div id=isLink><Script>document.write(linkStr)</Script></Div>
</Body>
</HTML>
I tried the solution you gave me, but I encountered errors in implementing it. I got an error saying the variable was not defined.
I actually think you have a solution that will work for me. The only further questions i have is:
1) do i just add more "linkURL"s for more links?
2) if i need the +currLink+ to populate over a multitude of other links (ie more qksv.net links) do i just copy, paste, and modify for a multitude of links.
<HTML>
<Head>
<Script Language=JavaScript>
isWidth = screen.availWidth;
isHeight = screen.availHeight;
window.resizeTo(isWidth,isHeight);
window.moveTo(0,0);
var currLink = window.name;
linkURL = new Array();
linkURL[0] = "/A_Link.html"
linkURL[1] = "/B_link.html"
linkURL[2] = "/C_Link.html"
if (currLink == 'A'){currLink = linkURL[0]}
if (currLink == 'B'){currLink = linkURL[1]}
if (currLink == 'C'){currLink = linkURL[2]}
var linkStr = "<a href=http://www.qksrv.net/click"+currLink+" target='_blank'>Link</a>"
</Script>
</Head>
<Body>
<Div id=isLink><Script>document.write(linkStr)</Script></Div>
</Body>
</HTML>
<a href="http://www.qksrv.net/some.html" target="_blank" NAME='A'>Link</a>
<a href="http://www.qksrv.net/some.html" target="_blank" NAME='B'>Link</a>
<a href="http://www.qksrv.net/some.html" target="_blank" NAME='C'>Link</a>
The original code seems to work. I was having trouble publishing the code, hence my problems. If I can bother you once more, the final issue I have is how do I make this work with a drop down menu. i.e. I have the "A" "B" and "C" links within a drop down menu, and I want this code to work when a user selects one of the menu items.
I currently have it set up as a form with OnChange="location=getSelect(this)"
Thanks!
<HTML>
<Head>
<Script Language=JavaScript>
function nextPage(isList){
link = isList.options[isList.selectedIndex].value;
window.open("newPage.html",link);
}
</Script>
</Head>
<Body>
<center>
<br><br>
<select onChange="nextPage(this)">
<option selected> Make a selection </option>
<option value='A'> Steel </option>
<option value='B'> Iron </option>
<option value='C'> Lead </option>
</select>
</center>
</Body>
</HTML>