SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: How do I do this?
-
Mar 27, 2008, 07:57 #1
- Join Date
- Aug 2007
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do I do this?
I know very little about JavaScript, so I would like someone to point me in the right direction so I can go research what I need to do and figure it out. Right now I am just walking around in the dark.
On this site: http://kittenwar.com you click on a picture to vote for it. I understand how to do that, what I want to figure out is how the picture that doesn't get clicked gets a losing vote.
So, no matter which picture gets clicked, they both get votes...one winner and one looser.
I am Rails guy, so I understand how to setup the database and everything else, I just don't know where to start with the JavaScript. Thanks.
-
Mar 27, 2008, 08:28 #2
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
how the picture that doesn't get clicked gets a losing vote
Code:<form> <input type="hidden" name="kitten1" value="loser"> <input type="hidden" name="kitten2" value="loser"> <input type="image" src="kitten1.jpg" onclick="this.form.kitten1.value='winner'"> <input type="image" src="kitten2.jpg" onclick="this.form.kitten2.value='winner'"> </form>
one tighter and one looser
-
Mar 27, 2008, 08:37 #3
-
Mar 27, 2008, 09:48 #4
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wouldn't it be easier to just set the name of the winner in a hidden field? Then you know that all the other ones are losers and you can withdraw a point from them.
-
Mar 27, 2008, 10:03 #5
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh, its only two kittens I see now.
No hidden field is necessary, just use 2 inputs of type image and give each input a name that will be submitted.
This solution would also make all the scared people surfing with JavaScript off happy.
-
Mar 27, 2008, 11:02 #6
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, if the kittens were chosen at random from a database (likely) then the server page wouldn't necessarily know which two they were, so you'd need 2 inputs submitted.
-
Mar 27, 2008, 11:32 #7
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, then simply set the ID of that kitten as a value on the input type image.
Bookmarks