From: venu madhav on 7 Feb 2010 08:15 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.
From: Gregor Kofler on 7 Feb 2010 11:09 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 -- http://www.gregorkofler.com
From: Thomas 'PointedEars' Lahn on 7 Feb 2010 12:43 Gregor Kofler wrote: > venu madhav meinte: >> I have a problem invoking a Java Script function inside a >> href function. > > It is either JavaScript or ECMAScript. If "JavaScript" is understood as a name for all ECMAScript implementations. > And there is no "href function". ACK >> 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')) { 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 -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: Hans-Georg Michna on 7 Feb 2010 13:41 On Sun, 7 Feb 2010 05:15:32 -0800 (PST), venu madhav wrote: > 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. What is sethelplink supposed to do? Or do you just want a time-dependent string in the URL and sethelplink is unrelated? 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. 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
From: venu madhav on 7 Feb 2010 20:05 On Feb 7, 11:41 pm, Hans-Georg Michna <hans- georgNoEmailPle...(a)michna.com> wrote: > On Sun, 7 Feb 2010 05:15:32 -0800 (PST), venu madhav wrote: > > 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. > > 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
|
Next
|
Last
Pages: 1 2 Prev: document.write with "li" in IE end tags disappear Next: Would you stop for a moment?! |