How to call a java script function in href?

V

venu madhav

Hi all,
I have a problem invoking a Java Script function inside a
href function. I've to pass the return value of a java script function
as an input to the script which is invoked using href in anchor tag.
The problem is the function is not getting invoked. Here is my code:

<a class="innerliks_sub1" href='/ems/cgi-bin/wips/wips_dashboard.cgi?
current_time='+Math.round(new Date().getTime()) target="icc"
onClick="sethelplink('dashboard')"> Dashboard </a>


Can some one help me how to pass the value to that cgi? Pls let me
know if you need any clarifications.
 
G

Gregor Kofler

venu madhav meinte:
Hi all,
I have a problem invoking a Java Script function inside a
href function.

It is either JavaScript or ECMAScript. And there is no "href function".
I've to pass the return value of a java script function
as an input to the script which is invoked using href in anchor tag.
The problem is the function is not getting invoked. Here is my code:

<a class="innerliks_sub1" href='/ems/cgi-bin/wips/wips_dashboard.cgi?
current_time='+Math.round(new Date().getTime()) target="icc"
onClick="sethelplink('dashboard')"> Dashboard </a>

What does the click listener do? And the attribute is properly spelled
"onclick". (Why one needs to submit some date/time via an URI to a
server is beyond me, anyway.)

Untested:
<a ... href='/ems/cgi-bin/wips/wips_dashboard.cgi'
onclick="
if(sethelplink('dashboard')) {
this.href = this.href +
'?current_time='+Math.round(new Date().getTime();
return true;
}
">

Gregor
 
T

Thomas 'PointedEars' Lahn

Gregor said:
venu madhav meinte:

It is either JavaScript or ECMAScript.

If "JavaScript" is understood as a name for all ECMAScript implementations.
And there is no "href function".
ACK


What does the click listener do? And the attribute is properly spelled
"onclick". (Why one needs to submit some date/time via an URI to a
server is beyond me, anyway.)

Untested:
<a ... href='/ems/cgi-bin/wips/wips_dashboard.cgi'
onclick="
if(sethelplink('dashboard')) {

Isn't that a bit too much to assume here?
this.href = this.href +

this.href +=
'?current_time='+Math.round(new Date().getTime();

You forgot the closing `)', but Math.round() does not make sense here
in the first place. And fast history navigation might turn this into
something really wrong.
return true;
}
">

With less assumptions, a bit more efficient and less error-prone:

<a ... href="/ems/cgi-bin/wips/wips_dashboard.cgi"
onclick="this.href = this.href.replace(/\?.*/, '')
+ '?current_time=' + (new Date()).getTime();
sethelplink('dashboard');"
Dashboard</a>


PointedEars
 
V

venu madhav

What is sethelplink supposed to do? Or do you just want a
time-dependent string in the URL and sethelplink is unrelated?

Thanks for the replies.. sethelplink() function is not related to what
we're doing but should be there.
By the way, the Math.round(...) looks superfluous. Just use new
Date().getTime() or a fraction of it, like new
Date().getTime().toString().slice(-9, -3) if seconds are good
enough, so the URL doesn't get needlessly long. But all this
does not work in the href value.

Yeah I can remove the Math.round() function. Thanks for the
suggestion.
My first thought would be not to use the href attribute, but put
everything into onclick and do it in a JavaScript function.

Depending on circumstances, an alternative could be to modify
href through JavaScript already after the page is loaded.
Doesn't look as enticing though.

Hans-Georg

But here the problem is there is a target defined for the href. If
you see "target=icc", that is where the target page loads into. "icc"
is a frame. So How can I load the page into this icc in the Java
script function
 
T

Thomas 'PointedEars' Lahn

venu said:
Hans-Georg Michna said:
What is sethelplink supposed to do? Or do you just want a
time-dependent string in the URL and sethelplink is unrelated?

Thanks for the replies.. sethelplink() function is not related to what
we're doing but should be there.
[...]
Depending on circumstances, an alternative could be to modify
href through JavaScript already after the page is loaded.
Doesn't look as enticing though.
[...]

But here the problem is there is a target defined for the href. If
you see "target=icc", that is where the target page loads into. "icc"
is a frame. So How can I load the page into this icc in the Java
script function

1. There is no "Java script"; the language is called JavaScript, one word.
(And it has little, if anything, to do with Java.)

2. Which function are you referring to?

3. You do not have to do anything to load the "page" into the frame
named "icc"; the `target' attribute already takes care of that.

However, if with client-side scripting the URI of the target resource
should be different than without scripting, you can modify the value
of the `href' attribute as suggested before.

4. As an alterative, it is possible to use the `window.frames' collection
to change the source of a frame, provided that the Same Origin
Policy (same protocol, same host name, same port) is met. For example:

<... onclick="window.frames['icc'].location = this.href
+ "?" + (new Date()).getTime();
return false"
...</...>

Please trim your quotations to the relevant minimum. Please do not
quote signatures. And please read the FAQ before posting here again:

<http://jibbering.com/faq/#posting>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top