Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternate onClick method???

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi
I have a button that activates a javascript when clicked. however, i find myself having to include the &quot;onclick&quot; in a <a href...> anchor tag.
The problem is, if I include it in an anchor tag, I'll have to make the link
<a href=&quot;#&quot;...> with just a # so that it doesn't go anywhere looking for a page.
Is there an alternate method to have the onclick and onmouseover... commands not using the anchor tag?
 
The way to do it is to use void() method as JavaScript:void(0):

<A HREF=&quot;JavaScript:void(0)&quot; ONCLICK=&quot;alert('Hi!')&quot;>Alert &quot;Hi!&quot;</A>


I've seen some people to it without the void() method:
<A HREF=&quot;JavaScript:&quot; ONCLICK=&quot;alert('Hi!')&quot;>Alert &quot;Hi!&quot;</A>
But it only works like you'd want it to in IE, in NS it opens the JavaScript debbuger window.

Is this what you were looking for?

-tleish
 
Well, the thing is, if i use the anchor tag, and after i click on it, in netscape, an hour glass will appear and if i keep my mouse still, hte hour glass will stay there...
I just want to find a way to get rid of that hour glass, and I believe it's the anchor tag's poblem.
 
I just tested again
the hour glass won't go away until I leave the button's &quot;field&quot;
meaning if I keep move my mouse on top of the button after clicking, it's always a hour glass cursor!
How can I get rid of it...
 
IE doesn't have the problem
I'm just testing with Netscape Communicator 4.76
this is my code that executes, the functoin is too long.

<a href=&quot;#onClick=&quot;senderCommand('Italic')&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image51','','images/toolover_italic.gif',1)&quot; onMouseDown=&quot;MM_swapImage('Image51','','images/tooldown_italic.gif',1)&quot;><img src=&quot;images/tool_italic.gif&quot; width=31 height=28 border=&quot;0&quot; name=&quot;Image51&quot; alt=Italic></a>

This problem exists for every anchor tag that only serves to activate a javascript (meaning not linked to any page)

You an try that with any function/anchortag
 
Did you try it this way?

<a href=&quot;JavaScript:void(0)&quot; onClick=&quot;senderCommand('Italic')&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image51','','images/toolover_italic.gif',1)&quot; onMouseDown=&quot;MM_swapImage('Image51','','images/tooldown_italic.gif',1)&quot;><img src=&quot;images/tool_italic.gif&quot; width=31 height=28 border=&quot;0&quot; name=&quot;Image51&quot; alt=Italic></a>

I'm not able to douplicate the same problem. Can you put it somewhere where I can view the page?

 
I have inserted text link that doest the same onClick, but it's fine with text.
Could it simply be a problem with netscape?
or there's a alternate method to get around this problem?
 
You can also use <a href=&quot;javascript:jsFunction();&quot;>here</a>
 
p|nky, I see your problem now. Just add &quot;return false&quot; after your call to the function.

<a href=&quot;JavaScript:void(0);&quot; onClick=&quot;testFunction();return false;&quot;><img src=&quot;a.gif&quot; width=93 height=84 border=&quot;0&quot; name=&quot;testimage&quot; alt=A></a>

That will get rid of the hour glass you are seeing in NS.
 
It works now!!
how did you figure that out?
I mean... can you explain to me what the problem is?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top