Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-03-2009, 10:02 PM   PM User | #1
ajhp3
New Coder

 
Join Date: Mar 2009
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
ajhp3 is an unknown quantity at this point
NCAA Tournament Bracket Script

Hey Everyone, I'm hoping you all can help me with this. I have created a html ncaa tournament bracket for my website in which I hold annual competitions. Recently, my competition has grown and I need a better way for users to submit their brackets.

What Im looking for is a way to allow the person filling out the bracket to click on their predicted winner for each game, which will then fill out the bracket as they move through the bracket until the have predicted a national champion.

Any Ideas?
ajhp3 is offline   Reply With Quote
Old 03-03-2009, 10:47 PM   PM User | #2
mknott
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
mknott is an unknown quantity at this point
What you could do is have drop down menu's and then when they submit the bracket then it will capture the values off there submitment.
mknott is offline   Reply With Quote
Old 03-03-2009, 11:10 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Sounds to me like you need a server side solution with a database backing.

That way you can automate the whole thing, including figuring out who the winners (your players, not the teams) are.

mknott has probably the right idea of the way to present the <FORM>, but it needs to be smarter than just simple drop downs. If you make them fill in the brackets from 64 to 2, then at each game there will only be two choices for the winner. If you allow "free form" fill in, then at the final game you'd have to have 32 teams in each of the dropdowns. Ugly. I think I'd avoid dropdown and just allow them to click on the winner from the pair of winners of the prior game.
Old Pedant is offline   Reply With Quote
Old 03-04-2009, 03:20 AM   PM User | #4
ajhp3
New Coder

 
Join Date: Mar 2009
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
ajhp3 is an unknown quantity at this point
Is there any way to get around the server without using the drop-down boxes?
ajhp3 is offline   Reply With Quote
Old 03-04-2009, 02:08 PM   PM User | #5
silvermoss
New to the CF scene

 
Join Date: Mar 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
silvermoss is an unknown quantity at this point
I am thinking what can be done is display all of the first rounds and have a button call a function roundOne() This will grab the submitted values and read them and the round two buttons will will read those values and write them into the form for roundTwo() and progress all the way until you get to a final. Is the final result going to be printed out and handed to you, or emailed or submitted in some other way?

You could also do this in excel if really wanted to do it in an easy way, then you can save that as an interactive excel file. This is the javascript forum and that is the fun in the challenge.

If I get a little more free time I will try to get some sample code for you, though the idea may get you going in the right direction.
silvermoss is offline   Reply With Quote
Old 03-04-2009, 07:36 PM   PM User | #6
ajhp3
New Coder

 
Join Date: Mar 2009
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
ajhp3 is an unknown quantity at this point
Results

Yes the final results will be emailed to me, which will then be printed off for records keeping.
ajhp3 is offline   Reply With Quote
Old 03-04-2009, 10:34 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Oh, W.T.H. -- here...

Only 4 teams instead of 64, but it shows the concept.

It's not terribly sophisticated. If you choose "Amherst" and "Connecticut" as winners, they show up in the round of 32. Then you click on Connecticut there and it shows up in sweet 16. But if you go back to first round and click on Duke, it changes round of 32 fine but leaves Connecticut in sweet 16. But all that, too, could be fixed with a tad bit of JS coding.

Not to ask a dumbass question, but...HOW will the results get EMailed to you????
Code:
<html>
<head>
<style>
td.team { border: solid blue 2px; background-color: lightblue; width: 120px; height: 24px; 
          font-family: arial, helvetica; font-size: 12px; 
        }
</style>
<script>
function win(winner,nextgame)
{
    var team = winner.innerHTML;
    document.getElementById("WIN"+nextgame).innerHTML = team;
}
</script>
</head>
<body>
<table border=0 cellpadding=3>
<tr>
    <td class="team" onclick="win(this,1)">Amherst</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN1" onclick="win(this,33)">&nbsp;</td>

</tr>
<tr>
    <td class="team" onclick="win(this,1)">Bowling Green</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td class="team" id="WIN33">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,2)">Connecticut</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN2" onclick="win(this,33)">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,2)">Duke</td>
</tr>
</table>
</body>
Old Pedant is offline   Reply With Quote
Old 03-05-2009, 12:54 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Here you go...a better version.

If you have (example) Connecticut picked to go all the way and then change your mind and think they will lose to Duke, then Duke gets propagated all the way up.

This only shows 8 teams at first level, but obviously easy to extend to 64.

Note the numbering scheme for the "WINx_y" button names: x is the level. 0 for entry, 1 for 1 win, 2 for 2 wins, etc. y is just the game number *IN THAT ROUND*. So "WIN6_1" will show the user's choice for champion. (Of course won't be any "WIN6_2".)

Essentially, what I show here is the teams that would pick one winner for the Elite Eight.

NOTE: I do *NOT* handle the "play-in" game. Too much trouble. Just code it by itself.

Code:
<html>
<head>
<style>
.team { border: solid blue 2px; background-color: lightblue; width: 120px; height: 24px; 
        font-family: arial, helvetica; font-size: 12px; 
      }
</style>
<script>
function win(winner)
{
    var team = winner.value;
    var levels = winner.name.substring(3).split("_");
    var curlevel = parseInt(levels[0]);
    var curgame  = parseInt(levels[1]);

    var nextlevel = curlevel + 1;
    var nextgame  = Math.floor( (curgame+1) / 2 );
    
    var winnerButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
    if ( winnerButton == null ) return;

    ++nextlevel;
    nextgame  = Math.floor( (nextgame+1) / 2 );
    var nextButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
    var forward = ( nextButton != null && nextButton.value == winnerButton.value );

    winnerButton.value = team;
    if ( forward ) winnerButton.click( );
}
</script>
</head>
<body>
<form>
<table border=0 cellpadding=3>
<tr>
    <td><input type=button class="team" name="WIN0_1" onclick="win(this)" value="Amherst"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_1" onclick="win(this)" value=""></td>

</tr>
<tr>
    <td><input type=button class="team" name="WIN0_2" onclick="win(this)" value="Bowling Green"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team" name="WIN2_1" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_3" onclick="win(this)" value="Connecticut"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_2" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_4" onclick="win(this)" value="Duke"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team" name="WIN3_1" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_5" onclick="win(this)" value="Elmira"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_3" onclick="win(this)" value=""></td>

</tr>
<tr>
    <td><input type=button class="team" name="WIN0_6" onclick="win(this)" value="Florida"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team" name="WIN2_2" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_7" onclick="win(this)" value="Georgetown"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_4" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_8" onclick="win(this)" value="Hawaii"></td>
</tr>

</table>
</form>
</body>
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
ajhp3 (03-05-2009)
Old 03-05-2009, 01:00 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Silvermoss: Yeah, right idea. But why bother with a different function for each round???

See my code: I just a "naming convention" so that I can always figure out which "slot" the clicked on winner goes into. And then I even use recursion if I need to replace the next level up, too. Ad nauseum.

But I'm still not sure what format the email can/will be in. Hmmm....
Old Pedant is offline   Reply With Quote
Old 03-05-2009, 03:54 AM   PM User | #10
ajhp3
New Coder

 
Join Date: Mar 2009
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
ajhp3 is an unknown quantity at this point
Thanks

Hey thanks for the help!

This definately gives me a starting point on this project. A little bit of tweeking here and there and it will shine.

As far as the emailing part goes, not quite sure about that yet. However, I have to come up with some way of getting the information.

Aaron
ajhp3 is offline   Reply With Quote
Old 03-05-2009, 09:32 PM   PM User | #11
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Collecting all the <form> fields and then emailing from them would be an easy server-side project in ASP/PHP/JSP/ASP.NET.
Old Pedant is offline   Reply With Quote
Old 03-06-2009, 03:25 AM   PM User | #12
ajhp3
New Coder

 
Join Date: Mar 2009
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
ajhp3 is an unknown quantity at this point
Still Missing Something

Thanks for all the help Old Pedant. However, I have hit another issue that i cant seem to figure out, although maybe im just looking at it too hard and not stepping back to take a look at it. Ive been working day and night on this website to try and get it ready and i only have a couple of weeks left.

I have taken your code that you started with and expanded it to a 16 team bracket. However, for some reason, i cant seem to figure out how to add a 3rd and a 4th round to the bracket. Ive been racking my brain on this and other things and im basically exhausted.

So far I have attempted to add the third round to the bracket, but it doesnt seem to want to show the results of third round game. what am i doing wrong?

Code:
<html>
<head>
<style>
td.team { border: solid blue 2px; background-color: lightblue; width: 120px; height: 24px; 
          font-family: arial, helvetica; font-size: 12px; 
        }
</style>
<script>
function win(winner,nextgame)
{
    var team = winner.innerHTML;
    document.getElementById("WIN"+nextgame).innerHTML = team;
}
</script>
</head>
<body>
<table border=0 cellpadding=3>
<tr>
    <td class="team" onclick="win(this,1)">1. Amherst</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN1" onclick="win(this,33)">&nbsp;</td>

</tr>
<tr>
    <td class="team" onclick="win(this,1)">16. Bowling Green</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td class="team" id="WIN33">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,2)">8. Connecticut</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN2" onclick="win(this,33)">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,2)">9. Duke</td>
</tr>
<tr>
    <td class="team" onclick="win(this,3)">5. Michigan</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN3" onclick="win(this,34)">&nbsp;</td>

</tr>
<tr>
    <td class="team" onclick="win(this,3)">12. Alabama</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td class="team" id="WIN34">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,4)">2. Michigan State</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN4" onclick="win(this,34)">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,4)">15. Alcorn State</td>
</tr>
<tr>
    <td class="team" onclick="win(this,5)">4. Pittsburgh</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN5" onclick="win(this,35)">&nbsp;</td>

</tr>
<tr>
    <td class="team" onclick="win(this,5)">13. Minnesota</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td class="team" id="WIN35">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,6)">6. Purdue</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN6" onclick="win(this,35)">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,6)">11. Wisconsin</td>
</tr>
<tr>
    <td class="team" onclick="win(this,7)">3. Illinois</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN7" onclick="win(this,36)">&nbsp;</td>

</tr>
<tr>
    <td class="team" onclick="win(this,7)">14. Miami</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td class="team" id="WIN36">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,8)">7. Maryland</td>
</tr>
<tr>
    <td></td>
    <td class="team" id="WIN8" onclick="win(this,36)">&nbsp;</td>
</tr>
<tr>
    <td class="team" onclick="win(this,8)">10. North Carolina</td>
</tr>
</table>
</body>
ajhp3 is offline   Reply With Quote
Old 03-06-2009, 05:19 AM   PM User | #13
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
No no no...use that second post of mine. The "better" version. It really is much better in several ways.
Old Pedant is offline   Reply With Quote
Old 03-06-2009, 07:01 AM   PM User | #14
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Here...one full region and more...

Here's a 16-team region in its entirety plus the "final four" spots and final game matchup just for clarity.

All you'd have to do would be to "clone" the one region--be sure to renumber the field names in the other regions according to my pattern--and you'd be good to go.

It makes a really long HTML page. You probably could make it half as long by putting regions on both left and right side, by tightening up the spacing, but I dunno that it's worth it.
Code:
<html>
<head>
<style>
*     { font-family: arial; font-size: 12px; }
th    { border: solid blue 3px; background-color: yellow; font-size: 16px; }
.team { border: solid blue 2px; background-color: lightblue; width: 120px; height: 24px; }
.team2 { border: solid brown 2px; background-color: wheat; width: 120px; height: 24px; }
.team3 { border: solid red 2px; background-color: pink; width: 120px; height: 24px; }
</style>
<script>
function win(winner)
{
    var team = winner.value;
    var levels = winner.name.substring(3).split("_");
    var curlevel = parseInt(levels[0]);
    var curgame  = parseInt(levels[1]);

    var nextlevel = curlevel + 1;
    var nextgame  = Math.floor( (curgame+1) / 2 );
    
    var winnerButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
    if ( winnerButton == null ) return;

    ++nextlevel;
    nextgame  = Math.floor( (nextgame+1) / 2 );
    var nextButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
    var forward = ( nextButton != null && nextButton.value == winnerButton.value );

    winnerButton.value = team;
    if ( forward ) winnerButton.click( );
}
</script>
</head>
<body>
<form>
<table border=0 cellpadding=0>
<tr>
	<th colspan=4 style="font-size: x-large;">West Region</th>
	<th colspan=3 style="font-size: x-large;">Final Four</th>
</tr>
<tr>
	<th colspan=2>Sub-Regional #1</th>
	<th colspan=2 style="background-color: wheat;">Regional Final</th>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_1" onclick="win(this)" value="#1 Seed"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_1" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_2" onclick="win(this)" value="#16 Seed"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team2" name="WIN2_1" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_3" onclick="win(this)" value="#8 Seed"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_2" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_4" onclick="win(this)" value="#9 Seed"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team2" name="WIN3_1" onclick="win(this)" value=""></td>
</tr>
<tr>
	<th colspan=2>Sub-Regional #2</th>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_5" onclick="win(this)" value="#4 Seed"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_3" onclick="win(this)" value=""></td>

</tr>
<tr>
    <td><input type=button class="team" name="WIN0_6" onclick="win(this)" value="#13 Seed"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team2" name="WIN2_2" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_7" onclick="win(this)" value="#5 Seed"></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_4" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_8" onclick="win(this)" value="#12 Seed"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team3" name="WIN4_1" onclick="win(this)" value=""></td>
</tr>
<tr>
	<th colspan=2>Sub-Regional #3</th>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_9" onclick="win(this)" value="#3 Seed" ></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_5" onclick="win(this)" value="" ></td>

</tr>
<tr>
    <td><input type=button class="team" name="WIN0_10" onclick="win(this)" value="#14 Seed" ></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team2" name="WIN2_3" onclick="win(this)" value="" ></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_11" onclick="win(this)" value="#6 Seed" ></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_6" onclick="win(this)" value="" ></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_12" onclick="win(this)" value="#11 Seed" ></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team2" name="WIN3_2" onclick="win(this)" value="" ></td>
</tr>
<tr>
	<th colspan=2>Sub-Regional #4</th>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_13" onclick="win(this)" value="#2 Seed" ></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_7" onclick="win(this)" value="" ></td>

</tr>
<tr>
    <td><input type=button class="team" name="WIN0_14" onclick="win(this)" value="#15 Seed" ></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team2" name="WIN2_4" onclick="win(this)" value="" ></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_15" onclick="win(this)" value="#7 Seed" ></td>
</tr>
<tr>
    <td></td>
    <td><input type=button class="team" name="WIN1_8" onclick="win(this)" value="" ></td>
</tr>
<tr>
    <td><input type=button class="team" name="WIN0_16" onclick="win(this)" value="#10 Seed" ></td>
</tr>
<tr>
	<td colspan=8>and the other 3 regions...each with a regional winner</td>
</tr>
<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td><input type=button class="team3" name="WIN5_1" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team3" name="WIN4_2" onclick="win(this)" value="region #2 winner"></td>
</tr>
<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td colspan=2 style="font-size: 20px; text-align: right;">CHAMPION:&nbsp;&nbsp;</td>
    <td><input type=button class="team" 
               style="width: 160px; font-size: 20px; background-color: orange; height: 32px;"
               name="WIN6_1" onclick="win(this)" value=""></td>
</tr>

<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team3" name="WIN4_3" onclick="win(this)" value="region #3 winner"></td>
</tr>
<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td><input type=button class="team3" name="WIN5_2" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=button class="team3" name="WIN4_4" onclick="win(this)" value="region #4 winner"></td>
</tr>
</table>
</form>
</body>
Old Pedant is offline   Reply With Quote
Old 03-08-2009, 10:22 AM   PM User | #15
mbrewer
New Coder

 
Join Date: Mar 2009
Location: Bakersfield, CA
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post
mbrewer is an unknown quantity at this point
First of all I want to thank Old Pedant for this code as this gave me a great start after spending many hours searching the web and trying others examples and code.

I was messing around with the code and made a couple of changes with regards to the propogation of picks. When you make your first pick it really shouldn't propogate through all rounds, only the next round. I made the change and then realized that there are cases when you have made all your picks already and then change your mind and the team you are removing stays in future rounds, so I made a some more changes to check for the presence of the "old" team in future rounds and remove it. I tested and didn't see any bugs, but if I forgot something let me know.

function win(winner)
{
var team = winner.value;
var levels = winner.name.substring(3).split("_");
var curlevel = parseInt(levels[0]);
var curgame = parseInt(levels[1]);

var nextlevel = curlevel + 1;
var nextgame = Math.floor( (curgame+1) / 2 );

var curteam = winner.form.elements["WIN"+nextlevel+"_"+nextgame].value;
var winnerButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
if ( winnerButton == null ) return;

++nextlevel;
nextgame = Math.floor( (nextgame+1) / 2 );
var nextButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
var forward = ( nextButton != null && nextButton.value == winnerButton.value );

winnerButton.value = team;
while ( forward ) {
nextButton.value = " ";
++nextlevel;
nextgame = Math.floor( (nextgame+1) / 2 );
nextButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame];
forward = ( nextButton != null && nextButton.value == curteam );
}
}
mbrewer is offline   Reply With Quote
Reply

Bookmarks

Tags
codes, javascript, ncaa tournament, onclick

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 06:22 AM.


Advertisement
Log in to turn off these ads.