Posts: 159
Location: Skegness, Lincolnshire, England
|
You don't really need to store the info in a variable, all you need is the onClick() statement that changes the original to the new image, and that's it. If you want to make a function that uses a variable to determine the state of the button, taking 0 to be the original state of the button, and 1 to indicate that it has been clicked, simply use:
HTML Code:
<script language="Javascript">
var button_state = 0;
function swap_button() {
if (button_state == 0) {
// your normal button swap routine
// any additional execute once code
}
}
</script>
Use of the global variable button_state means that the new button image will only be used the once, and the swap will only occur once. Additionally, using this variable to bypass the swap routine means that you can also incorporate any other code you want to only be executed once when the button is first clicked.
Your button will of course still be clickable, but it will only execute the code after the if statement the first time it is clicked.
|