Forum Moderators: open

Message Too Old, No Replies

HTML 'clicked' buttons style

         

sebana

8:57 am on Jul 14, 2008 (gmt 0)

10+ Year Member



hi everyone, any idea on how to achieve the effect of having a HTML button remaining 'clicked down' on click, and 'clicked up' on another click? the effect is a 'held down' button to show selection, much like a checked checkbox.

any help is appreciated! thanks!

lavazza

3:18 am on Jul 15, 2008 (gmt 0)

10+ Year Member



I'm not entirely sure what it is your after

Hopefully the following file will illustrate 2 possible approaches


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>clicked buttons style</title>
<style type="text/css">
input[type=button] {
width:12.25em;
}
.myDefaultButton{
color:#333;
background:#999;
}
a input[type=button] {
color:#333;
background:#999;
}
a:active input[type=button] {
color:#666;
background:#ccc;
}
.myClickedButton{
color:#666;
background:#ccc;
}
</style>
<script type="text/javascript">
function myOnloadEvent()
{
document.myFormName.btn01.className='myDefaultButton';
document.myFormName.btn02.className='myDefaultButton';
}
function changeMyClassName(theButton)
{
myButtonID = theButton.id;
if(document.getElementById(myButtonID).className=='myClickedButton')
{
document.getElementById(myButtonID).className='myDefaultButton';
}
else
{
document.getElementById(myButtonID).className='myClickedButton';
}
}
</script>
</head>
<body onLoad="myOnloadEvent();">
<form name="myFormName" method="get" action=" ">
<h1>
<a href="http://www.webmasterworld.com/html/3697821.htm"
title="WebmasterWorld &raquo; HTML and Browsers &raquo; HTML 'clicked' buttons style ">
changeMyClassName() </a>
</h1>
<p>
<a href="#" title="sdfasfd">
<input id="btn00"
type="button"
value="Button 00"></a>
&nbsp; changes class name when active (mouse is clicked)
<br><br>
<input id="btn01"
type="button"
value="Button 01"
onClick="changeMyClassName(this);">
&nbsp; changes class name when clicked (and stays changed until clicked again)
</p>
</form>
</body>
</html>

sebana

4:06 am on Jul 15, 2008 (gmt 0)

10+ Year Member



thanks lava! i'm immensely thankful for you having to come up with a working code for me! is there a way to do this without CSS? because the buttons appear differently across different browsers..