PDA

View Full Version : OnClick change multiple links


mwijbenga
02-25-2004, 10:37 AM
Hya!

I have a problem with this webpage im building.
I have a menu which stands in the top frame, and in that same top frame i have a couple of other buttons.

I have 2 links; 1 is called search and 1 called offer.
When i click search i want all of the "other buttons" in the menu to get another URL. And when i click offer i want all of the just changed URLS to change again.

Ive used PHP to achieve this but this isnt really a good workaround since i have to reload the page, and other things, already loaded by javascript get reset again (for instance an onclick which shows an image on the left when you click it)

Is there a good way to do this?

You can check out the page at www.mobiel500.nl/dev/ for the source code.


Thanks in advance!

agent002
02-25-2004, 10:42 AM
Try editing this JavaScript to your needs, it goes between the <head> and </head> tags:
<script type="text/javascript"><!--

function ChangeSearch(){
document.getElementById('somelink1').href = 'other href here';
document.getElementById('somelink2').href = 'other href here';
// etc...
}

function ChangeOffer(){
document.getElementById('somelink1').href = 'other href here';
document.getElementById('somelink2').href = 'other href here';
// etc...
}

--></script>
Then use this code for your links:
<a href="#" onclick="ChangeSearch(); return false;">Search</a><br>
<a href="#" onclick="ChangeOffer(); return false;">Offer</a><br><br>

<a href="http://www.google.com" id="somelink1">Some link 1</a><br>
<a href="http://www.altavista.com" id="somelink2">Some link 2</a><br>
etc...

mwijbenga
02-26-2004, 03:30 AM
yes it's almost working.
the only thing i need now is that it loads the page it has to load in a lower frame. And i want it not to be in OnClick since there's already something in the onclick.
If i put it in the href i get errors (something like "return instruction is located out of the function" (sorry for the crappy translation, i get errors in dutch and i dont think they will tell you anything).

How can i achieve this?

Thanks a mil!

agent002
02-26-2004, 07:55 AM
So you want the 'offer' and 'search' links to be in frame1, and the links to change in frame2? Ok, this is the JavaScript function, put it in the frame with the Search and Offer links. Remember to change 'frame2' (as I suppose your frame isn't named frame2).
<script type="text/javascript"><!--

function ChangeSearch(){
parent.frame2.document.getElementById('somelink1').href = 'other href here';
parent.frame2.document.getElementById('somelink2').href = 'other href here';
// etc...
}

function ChangeOffer(){
parent.frame2.document.getElementById('somelink1').href = 'other href here';
parent.frame2.document.getElementById('somelink2').href = 'other href here';
// etc...
}

--></script>

You can have several functions called at the OnClick event. If you already have onclick to call This_Is_Some_Function(), then put a semicolor after it (if it doesn't have one already) and then ChangeSearch() or ChangeOffer():
onclick="This_Is_Some_Function(); ChangeSearch();"