Click to See Complete Forum and Search --> : using function in href


alizar
12-08-2002, 04:15 AM
I have an href which calls a javascript function which sets the window.location.href to another page with parameters as shown below. This works fine when clicked on but if someone tries to open the link in a new window using the right click, they get a javascript error 'object expected'. How can I do it?

<a href="javascript:displayTrend('CurrentL1','CurrentL2','CurrentL3','','Current Trend')">Current</a>

and the function looks like this:

<script type="text/javascript">
function displayTrend(field1, field2, field3, title)
{
var href;
href = "../Trends/TrendPage.asp?field1=" + field1;
if (field2 != "")
href += "&field2=" + field2;
if (field3 != "")
href += "&field3=" + field3;
href += "&min=" + parent.frames['basic_main'].minRec;
href += "&max=" + parent.frames['basic_main'].maxRec;
href += "&back=../basic/HarmonicHistory_frames.htm" ;
href += "&title=" + title;
href += "&firsttime=1";

parent.location.href = href;
}
</script>

Stefan
12-08-2002, 05:24 AM
Originally posted by alizar
How can I do it?


The obvious solution is to not put your javascript in the href...
It's not supposed to be there at all.
Use onclick="" instead and end the script with a "return false;" to prevent the page from executing the href.

For what to put in the href, try placing a backup link that will alow a user with no JavaScript to get to about the same place as when you click the link with JS on...