PDA

View Full Version : Changing A Button Background Color



T22958
Mar 23rd, 2007, 03:29 AM
I want to change the background color of a button while a function is executing. At the start of the function I do:
document.FrontPage_Form1.B4.style.background = "#CC99FF";
At the end of the function I do:
document.FrontPage_Form1.B4.style.background = "#99FF66";

The only way I have gotten it to work is to put an alert("") before each color change. How can I get this to work without the alert("") statement?

iLLin
Mar 23rd, 2007, 03:49 AM
If this is all in one function, then your not going to see a change as it will happen to fast. Post up some more code and what your trying to accomplish and lets see if we can make it do what you intend.

T22958
Mar 23rd, 2007, 04:09 AM
The function takes quite a long time to run. I think it has something to do with a screen refresh that makes it work with the alert. Is there a command similar to what the alert command that does not put anything on the screen and the user does not know it is happening?

iLLin
Mar 23rd, 2007, 04:42 AM
I can't help if I don't know what your trying to do. But anything in that function will happen right then and there. Some actions in that function could take some time but that won't prevent it from running through all the code. I have learned that from using ajax and setting up preloaders for actions to take place. It would do exactly what your talking about so I had to redo it differently and setup oncomplete functions.

iLLin
Mar 23rd, 2007, 04:43 AM
Oh and the "alert" halts the script, that is why you see it work. I did that too :p

brandonH
Mar 23rd, 2007, 05:14 AM
at the end of the function use a setTimeout() to reset the color of the button.


setTimeout("document.FrontPage_Form1.B4.style.background='#99FF66'",1000);

the 1000 is how many milliseconds of a delay you get 1000=1 second

iLLin
Mar 23rd, 2007, 05:20 AM
Yea you can use a delay to accomplish this but an oncomplete would be the "correct" way as it would be when its actually completed and not when the delay is up. But thats entirely up to you :)