Page 1 of 1
[SOLVED]Javscript help needed, link using top.location
Posted: Wed Aug 15, 2007 8:53 am
by rsmarsha
I have the following link which works fine in everything apart from IE6. In most browsers it takes a value from an adjacent text box and passes that along with the rest of the link to the intended page.
In IE6 it does nothing.
Code: Select all
<a href="javascript://" onClick="top.location='cart.php?xCmd=add&position=<?php echo $cr['productID']; ?>&xFwd=customer.php?xCmd=wlshow&xProd=<?php echo $cr['productID'];?>&qty<?php echo $cr['productID'];?>='+document.getElementById('qty<?php echo $cr['productID'];?>').value" />
Any ideas? help urgently needed and thanks in advance.

Posted: Wed Aug 15, 2007 8:57 am
by feyd
I would suspect it has something to do with your href.
Posted: Wed Aug 15, 2007 8:59 am
by rsmarsha
Yeah i'm not an expert in javascript, was told to do the link this way to get it to do what i wanted. Works fine in ie7/firefox/opera. Any tips on what to do to fix it?
Posted: Wed Aug 15, 2007 9:03 am
by VladSun
1. Listen to what feyd says
2. I use location.replace() instead of location= . Maybe that is the problem.
Re: Javscript help needed, link using top.location
Posted: Wed Aug 15, 2007 9:04 am
by superdezign
I could see IE choking on that.
Posted: Wed Aug 15, 2007 9:09 am
by rsmarsha
I am listening, but the fact it's a problem with my href, doesn't get me any further. I need to get this one fixed quickly, i'm googling it as well as posting here, tried a few things. A pointer will help.
Thanks in advance for any tips.
On a side note , like the "A world without IE" site, superdezign.

Posted: Wed Aug 15, 2007 9:11 am
by VladSun
Code: Select all
<a href="javascript:top.location='cart.php?xCmd=add&posit.......' ">
, no onclick
or
, and your code for onclick
Posted: Wed Aug 15, 2007 9:55 am
by rsmarsha
That last one has fixed it, thanks VladSun.
Posted: Wed Aug 15, 2007 9:57 am
by superdezign
rsmarsha wrote:I am listening, but the fact it's a problem with my href, doesn't get me any further.
It should. It just means use a different one. Whenever your URL begins with 'javascript:' the browser assumes that anything after it is a JavaScript command. Firefox and IE have different error handling techniques, and I'd bet that IE6 just.. chokes.
The JavaScript command '//' would just be a syntax error. Maybe you want 'javascript:void(0)' or use a regular URL, and just add a 'return false' to the end of your onClick.
rsmarsha wrote:On a side note , like the "A world without IE" site, superdezign.


Posted: Wed Aug 15, 2007 9:58 am
by superdezign
rsmarsha wrote:That last one has fixed it, thanks VladSun.
Note that if you don't use 'return false,' that the browser will still follow the link, which would likely make you navigate to the top of the page every time you click.
Posted: Wed Aug 15, 2007 10:04 am
by VladSun
0. Listen to superdezign too

1. In fact, I would never use onclick in an anchor tag in your case - you are overwriting exisitng functionality - the href="javascript:code" param.
Posted: Wed Aug 15, 2007 11:13 am
by rsmarsha
Thanks again all.
