mouseover

I have this code:
<img src="images/home_button.gif" onmouseover="this.src='images/home_button2.gif'" onmouseout="this.src='images/home_button.gif'" />

How to I make sure the image stays at home_button2.gif after user click on it?
LVL 2
rolandmyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
You have to do a bit more work. Like:

// javascript part
var m_clicked = false;
function m_over(o) {
    this.src='images/home_button2.gif';
}

function m_out(o) {
    if (m_clicked) {
        this.src='images/home_button2.gif';
    } else {
        this.src='images/home_button.gif';
    }
}

function m_click(o) {
    m_clicked = true;
}

// html
<img src="images/home_button.gif" onmouseover="m_over(this)" onmouseout="m_out(this)" onclick="m_click(this)"/>

Open in new window

0
rolandmyAuthor Commented:
mouseover not working in the code provided. Also, I have more than 1 buttons in the menu..
0
StingRaYCommented:
// javascript part
function m_over(o) {
    o.src='images/home_button2.gif';
}

function m_out(o) {
    if (o.clicked) {
        o.src='images/home_button2.gif';
    } else {
        o.src='images/home_button.gif';
    }
}

function m_click(o) {
    o.clicked = true;
}

// html
<img src="images/home_button.gif" onmouseover="m_over(this)" onmouseout="m_out(this)" onclick="m_click(this)"/>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Atique AnsariCommented:
Just replace the http://localhost.... with your path.
<img src="images/Bluehills.jpg" onmouseover="if(this.src!='http://localhost/ee/images/Waterlilies.jpg'){ this.src='images/Sunset.jpg' }" onmouseout=" if(this.src!='http://localhost/ee/images/Waterlilies.jpg'){ this.src='images/Bluehills.jpg'}" onclick="this.src='images/Waterlilies.jpg'" />

Open in new window

0
Atique AnsariCommented:
Another solution is to store image clicked status in a variable.

Try attached code and let me know if you need more help.
<script language="javascript" type="text/javascript">
	var image_clicked	=	false;
</script>

<img src="images/Bluehills.jpg" onmouseover="if(!image_clicked){ this.src='images/Sunset.jpg' }" onmouseout=" if(!image_clicked){ this.src='images/Bluehills.jpg'}" onclick="image_clicked = true; this.src='images/Waterlilies.jpg';" />

Open in new window

0
rolandmyAuthor Commented:
Thanks all who replied. I just use if statement in php to switch the buttons. Will award points to both.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.