Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 3
Trades: 0
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
Please login or register to view this content. Registration is FREE
ZeeMan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-11-2005, 05:25 PM
onlyplace4's Avatar
Extreme Talker

Posts: 159
Location: Skegness, Lincolnshire, England
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.10071 seconds with 12 queries