two actions w/one button?

M

md75

Hello,
Having a little trouble figuring this one out. I need to have one button on
a page but have it toggle between two background colors. For example, when
the visitor first enters the page, the bg color would be blue. Then, if user
clicks on the button, bg color would be green. Last, if user clicks the same
button, bg color would toggle back to blue, and so on.

Any help on this matter would be greatly appreciated.

thanks, MMD
 
M

MD Websunlimited

Hi,

Use a little JavaScript to accomplish by testing the current background color and setting the other.

<input type="button" onclick="if(document.bgColor == '#0000ff') { document.bgColor='#00ff00' } else { document.bgColor='#0000ff' } "
 

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

Top