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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button question

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
US
Hello all,

I have sort of an interesting thing I'm trying to do. I have three generic form buttons and I want to make it so that when you push one button, it stays depressed. But I also want it so that when you push another button, the original button pops back up...so that only one button can be depressed at a time. I'm guessing there's some way in Javascript that can do it. Does anyone know how this is done?

Thanks,
Jisoo22
 
you can't actually control the up/down state of a button with js - what you can do is simulate the look with css:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>&quot;radio&quot; buttons</title>
<script type=&quot;text/javascript&quot;>
function rbClick(oButton) {
var btns = document.getElementsByName(&quot;rb&quot;);
for (var x = 0; x < btns.length; x++) {
if (btns[x] == oButton) btns[x].style.borderStyle = &quot;inset&quot;;
else btns[x].style.borderStyle = &quot;outset&quot;;
// comment the next line to allow button to retain focus
oButton.blur();
}
}
</script>
</head>

<body>
<form>
<input type=&quot;button&quot; name=&quot;rb&quot; value=&quot;one&quot; onclick=&quot;rbClick(this);&quot; />
<input type=&quot;button&quot; name=&quot;rb&quot; value=&quot;two&quot; onclick=&quot;rbClick(this);&quot; />
<input type=&quot;button&quot; name=&quot;rb&quot; value=&quot;three&quot; onclick=&quot;rbClick(this);&quot; />
</form>
</body>
</html>




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
You can load 2 images for each button
then use onlick to change the images.

Is that what you have in mind.

2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top