473,503 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button change colour by mouse action. Please help

123 New Member
I have something like below, normally when my mouse is over the button, it will change from less visible to visible, if mouse move away, it turn back to less visible.

But now i want to make it when i click the button, it will keep the status as visable even i move the mouse out from the button. Please help.

Thanks.

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT>
  2. function makevisible(cur,which){
  3. if (which==0)
  4. cur.filters.alpha.opacity=90
  5. else
  6. cur.filters.alpha.opacity=40
  7. if (which==2)
  8. cur.filters.alpha.opacity=0
  9. }
  10. </SCRIPT>
  11.  
[HTML]<button style="font-size: 9pt; color: gray; FILTER: alpha(opacity=40); background-color: gainsboro; border: 3px double gainsboro"
onmouseover="this.style.color='black'; makevisible(this,0)" onmouseout="this.style.color='gray'; makevisible(this,1)" onclick="listinfo()">List</button><br><br>[/HTML]
Nov 9 '07 #1
5 2269
Fisher ma
9 New Member
Hi,there is some code will help you on the below.

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT>
  2. function makevisible(cur,which){
  3. if (which==0)
  4. cur.filters.alpha.opacity=90
  5. else
  6. cur.filters.alpha.opacity=40
  7. if (which==2)
  8. cur.filters.alpha.opacity=0
  9. }
  10. function listinfo(el){
  11.     makevisible(el,0);
  12.     el.onmouseout = function(){
  13.     };
  14. }
  15. </SCRIPT>
  16.  
[HTML]<button style="font-size: 9pt; color: gray; FILTER: alpha(opacity=40); background-color: gainsboro; border: 3px double gainsboro"
onmouseover="this.style.color='black'; makevisible(this,0)" onmouseout="this.style.color='gray'; makevisible(this,1)" onclick="listinfo(this)">List</button><br><br>[/HTML]
Nov 9 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Please use code tags when posting code:

[CODE=javascript]
Your JavaScript code...
[/code]

Thanks!
Nov 9 '07 #3
perhapscwk
123 New Member
Thanks, it works, however, there is 2 button, i want to make it when i Click the 2nd button, then the first button will chnage to less invisible again?

Thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <button style="font-size: 9pt; color: gray; FILTER: alpha(opacity=40); background-color: gainsboro; border: 3px double gainsboro" 
  3. onmouseover="this.style.color='black'; makevisible(this,0)" onmouseout="this.style.color='gray'; makevisible(this,1)" onclick="generatenote(); listinfo(this)">Generate PCRM note</button><br><br>
  4. <button style="font-size: 9pt; color: gray; FILTER: alpha(opacity=40); background-color: gainsboro; border: 3px double gainsboro" 
  5. onmouseover="this.style.color='black'; makevisible(this,0)" onmouseout="this.style.color='gray'; makevisible(this,1)" onclick="generatemail(); listinfo(this)">Generate Email: Disti</button><br>
  6.  
  7.  
Nov 12 '07 #4
Dasty
101 Recognized Expert New Member
Your new condition changes solution quite a bit. So, you need to know which one button is in "clicked" state on general scope and old clicked button must be accessable (so we can turn it off). I think that easiest way would be to create global variable that holds object.id of last clicked button. (but it requires to set unique ids to all of your buttons). Solution would look like:

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT>
  2. var last_clicked_element_id = null;
  3.  
  4. function makevisible(cur,which){
  5.   if (which==0)
  6.   {
  7.     cur.style.color='black';
  8.     cur.filters.alpha.opacity=90;
  9.   }
  10.   else
  11.   {
  12.     if ((!cur.id) || (cur.id != last_clicked_element_id))
  13.     {
  14.       cur.style.color='gray';
  15.       cur.filters.alpha.opacity=40;
  16.     }
  17.   }
  18. }
  19.  
  20. function listinfo(cur)
  21. {
  22.   var old_selected = null;
  23.  
  24.   if (last_clicked_element_id)
  25.   {
  26.     old_selected = document.getElementById(last_clicked_element_id);
  27.   }
  28.   last_clicked_element_id = cur.id;
  29.   if (old_selected) makevisible(old_selected, 1)
  30.  
  31.   makevisible(cur,0);
  32. }</SCRIPT>
  33.  
[HTML]<button style="font-size: 9pt; color: gray; FILTER: alpha(opacity=40); background-color: gainsboro; border: 3px double gainsboro"
onmouseover="makevisible(this,0)"
onmouseout="makevisible(this,1)" onclick="listinfo(this)" id=button1>List1</button>
<br>
<button style="font-size: 9pt; color: gray; FILTER: alpha(opacity=40); background-color: gainsboro; border: 3px double gainsboro"
onmouseover="makevisible(this,0)"
onmouseout="makevisible(this,1)" onclick="listinfo(this)" id=button2>List2</button>[/HTML]

Yes, maybe we can do it better / faster by remembering reference to last clicked object (instead of its id), but this one is easier to understand and you can tune it up yourself.
Nov 12 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
Just a quick mention on cross-browser compatibility.

Use style.opacity (standard) to support the other browsers (e.g. Firefox, Opera, Safari) and style.mozOpacity to support older versions of Mozilla/Firefox.
Nov 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
43953
by: NONYA | last post by:
This is driving me crazy. I'm having trouble with how a simple radio button is displayed, in a simple html form. The default has the outline around the radio button shaded gray only in the top...
5
1427
by: Avni | last post by:
Can anyone tell me what event i would use to change the background colour of a button while the mouse is over the button. I could not find the mouseover event The colour will need to change back...
2
3386
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
7
7344
by: Tom Weston | last post by:
Hello Why are my buttons always Grey? how can I change the colour of the button? Tom
3
10599
by: Mel | last post by:
Hi, Is there any way I can force to change button background colour when toggle button is checked? Just like button change its background colour when mouseover in MS Visual Studio.NET. I hope I...
6
7588
Sushi
by: Sushi | last post by:
Hello! I'm new to the Python language(about 2 months). Having done C programming for 2 years I find out I need Python for a final project, and have been trying to do get my head around object...
5
2257
by: WestAussie | last post by:
Hello I'm new to .NET and have been working through some exercises to get a bit more fluent. I have no idea what I have done to cause command buttons to have their background appearance...
3
2577
by: bettyboo | last post by:
Hi I'm new to the forum and also a VERY new user of Access to develop databases. I'm building a DB for a driving instructor acquaintance, and he wants a button on the pupil data entry form which...
6
4502
by: gavy7210 | last post by:
hello i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk 1.5.. i have a login form(jsp) in which a user logs in,in case he doesnt enter his username and/or password an error...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.