Labcoatguy
Forum Addict
- Joined
- Mar 27, 2005
- Messages
- 14,181
- Location
- New England region, USA
- Car(s)
- #Jaguar #XKR #XJR, #Saab #9-3 #9-5 #900
Guess who's going to be #1 this year :lol:
I was rather bored the other day so I wrote a webscript.
http://jupix.info/fgcar2012/
The back end is about 90% done. Oh and I did change the point system to utilize whole integers and no decimals.
I would just need the help of someone who knows javascript... It is a far better solution to check the "ballot" before the user clicks submit, rather than only doing it in PHP when the form is processed. So, I would need javascript to check that there are under 10 (or 5) checkbox ticks in each category, and that those cars are only ticked in one category. If anyone could write it, that would be awesome.
I would just need the help of someone who knows javascript... It is a far better solution to check the "ballot" before the user clicks submit, rather than only doing it in PHP when the form is processed. So, I would need javascript to check that there are under 10 (or 5) checkbox ticks in each category, and that those cars are only ticked in one category. If anyone could write it, that would be awesome.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
// Bind some code to the form submit event
$("#votingform").submit(function(event) {
// Select all checked checkboxes and count them
var checked_count = $("#votingform input:checked").length;
// If there's too many checked...
if ( checked_count > 5 ) {
// Tell the user
alert( "You voted for " + checked_count + " items which is more than the 5 item maximum!" );
// And prevent the action from occurring (the form submission)
event.preventDefault();
}
});
});
</script>
Thats fantastic. To prevent cheating I was thinking about having members PM me for a special per user code then for them to use that to vote.
Give the <form> an ID of "votingform", i.e. <form id="votingform" ... > and then add this to your <head>:
(snip)
jQuery makes Javascript easy.
Note that of course you still need to enforce this on the PHP side too because someone could disable Javascript.
EDIT: Oh, I just noticed that the form is more complicated than I thought (people vote for their 1st, 2nd, and 3rd choices). You'll need to modify my code but it's easy enough. http://api.jquery.com/category/selectors/
Also I would randomly sort the cars on each page load so that there's no bias.
If you need any help with this, let me know. I literally do this (PHP development) for a living.
That's a real nice idea if you can be arsed to handle the pm thing. I coded the webapp under the assumption you'd had enough of the administrative overhead.
Thanks for your interest and effort so far! Unfortunately making the necessary modifications would require learning the js syntax and aforementioned library from scratch, which I don't have time for (or interest tbh) at present. The webapps I've written with php so far have utilized very little js and the few scripts I've used have been stock clips. If you could finish the script that would be awesome. I'm guessing to you it would be a breeze.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
// Bind some code to the form submit event
$("#votingform").submit(function(event) {
var max_votes_per_type = 5;
// Each grouping of checkboxes, identified by "name" value
var voting_types = new Array(
"v1_options",
"v2_options",
"v4_options" // No trailing comma! IE is a piece of shit
);
// Loop through each group
var array_len = voting_types.length;
for ( var i = 0; i < array_len; i++ ) {
// Select all checked checkboxes and count them
var checked_count = $("#votingform input[name='" + voting_types[i] + "[]']:checked").length;
// If there's too many checked...
if ( checked_count > max_votes_per_type ) {
// Tell the user
alert( "You voted for " + checked_count + " items in a single column which is more than the " + max_votes_per_type + " item maximum!" );
// And prevent the action from occurring (the form submission)
event.preventDefault();
// No need to check the other columns
return;
}
}
});
});
</script>
edit: mikas didn't want the columns shuffled with respect to each other so they are just "overall" random now
soooo.. Now that Viper's got his Viper hanging out, when's the nomination?