Reply
Making a button that changes when you click it
Old 07-11-2005, 02:59 PM Making a button that changes when you click it
Junior Talker

Posts: 3
I am working on a project to develop a voting system for use by schools or something and I am looking for a way to do something like this:

I know how to make the pictures swap but I want to make it so it will store the information in a variable and then when you click a button that says "Vote Now!".
In case you don't understand how this works:
The buttons normally all look like this:

But when you click one it changes to look like this:
__________________
My Website
ZeeMan is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-11-2005, 04:25 PM
onlyplace4's Avatar
Extreme Talker

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.
onlyplace4 is offline
Reply With Quote
View Public Profile Visit onlyplace4's homepage!
 
Reply     « Reply to Making a button that changes when you click it
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12272 seconds with 12 queries