# Solved: Using The "OnClick" Command



## BarraGT (Jun 21, 2005)

Is there a way to use two different "OnClick" commands for the one item, such as a link?

If I want an alert message to come up as well as to ensure that no status-bar text is displayed when a link is clicked, how could I do that?

Thanks.


----------



## brendandonhu (Jul 8, 2002)

Write a function to do both actions, and have onclick call that function.


----------



## BarraGT (Jun 21, 2005)

Can you give me an example of that?

I'm not overly familiar with JavaScript, so any further help would be appreciated.

If you could perhaps come up with the code to do what I've said above, I would really appreciate that!


----------



## drdrew1469 (Nov 30, 2000)

something like this?

asdf

window.status="" can/should be put in your body onload tag...

hth,

drew


----------



## BarraGT (Jun 21, 2005)

Are you able to show me the JavaScript code for a function that would make a link have no status-bar text when the mouse hovered over it, off it, or while it was being clicked?

I know that it can be done in the actual link code, but can you show me the JavaScript function?

Thanks for your help, too!


----------



## Rockn (Jul 29, 2001)

HERE


----------



## BarraGT (Jun 21, 2005)

Rockn said:


> HERE


That code is what I'm using now, and it doesn't quite do the trick.

That will still show the text in the status-bar when the link is clicked.

Also, can someone show me how to do all of that so I could place the code in an external JavaScript file and refer to it, rather than have all of those "onmouseover" code pieces in every link?


----------



## php guy (Dec 17, 2004)

Theres 2 ways you can do this:
Way 1, Have the javascript in the link itself
or 
Way 2, Have it stored in a function with an event handeler.

Way 1:

```
[URL=#]bla[/URL]
```
Way 2:

```
<html>
<head>
<script type="text/javascript">
function clickit()
{
alert('alert message');
window.status=' ';
}
</script>
</head>
<body>
<a href="#" onClick="clickit()">bla</a>
</body>
</html>
```
And about the external script, just copy everything inbetween , then save it into a file called script.js, then in the part, add

```
<script type="text/javascript" src="script.js">
```
 or what ever path to the .js file for the src="".


----------



## BarraGT (Jun 21, 2005)

php guy said:


> Theres 2 ways you can do this:
> Way 1, Have the javascript in the link itself
> or
> Way 2, Have it stored in a function with an event handeler.
> ...


Can that script also be referred to by an "onmouseover", "onmouseout", and "onclick", so that each one of those states will perform the same action?


----------



## php guy (Dec 17, 2004)

Yes, any event handlers can start the function.


----------



## BarraGT (Jun 21, 2005)

Okay, I've got a variation of this question.

What I want to have is a portion of JavaScript code that I can store in an external ".JS" file that will do the same things as this:


```
<a href="Page.htm" onclick="window.status='';return-false" onfocus="if(this.blur)this.blur()" onmousedown="window.status='';return-false" onmousemove="window.status='';return-false" onmouseout="window.status='';return-false" onmouseover="window.status='';return-false" onmouseup="window.status='';return-false">Page</a>
```
Is there a way that that can be translated into code that is similar to this type (for an external ".JS" file:


```
<script language="javascript" type="text/javascript">
function clickit()
{
alert('alert message');
window.status=' ';
}
</script>
```
So that I can just have something like this for all of the links where I want those effects applied:


```
<a href="#" onClick="clickit()">Text</a>
```


----------



## php guy (Dec 17, 2004)

Yep, it can all be stored externaly. If you want to use if for multiple links however, you have to change the function a bit. If you want all the links to do the same thing, keep it how it is... if not, try something like this...

```
<script language="javascript" type="text/javascript">
function clickit(alrt,msg)
{
alert(alrt);
window.status=msg;
}
</script>
```
Then for your links, write them just how you have it, except in the onClick="clickit()", write it as 

```
<a href="bla.htm" onClick="clickit('alert message here','Status bar message here');">
```


----------



## BarraGT (Jun 21, 2005)

Okay, cool. Thankyou for your help!


----------



## php guy (Dec 17, 2004)

No problem, just make sure you put the new function in the .JS file, and use the src="" in the head of your html.


----------

