Jump to content

Help with OR in Javascript?


galvin

Recommended Posts

I have this script for submitting picks for an NCAA-style bracket where you click a team and it shows up on the winners line in the next round (like you see on ESPN)....

 

<script>
function win(winner)
{
var team = winner.value;
var levels = winner.name.substring(4).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["pick"+nextlevel+"_"+nextgame].value;
var winnerButton = winner.form.elements["pick"+nextlevel+"_"+nextgame];
if ( winnerButton == null ) return;

++nextlevel;
nextgame = Math.floor( (nextgame+1) / 2 );
var nextButton = winner.form.elements["pick"+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["pick"+nextlevel+"_"+nextgame];
forward = ( nextButton != null && nextButton.value == curteam );
}
} 
</script>

and then the HTML is like this...

<tr>
    <td><input type=text readonly class="team" name="pick0_1" onclick="win(this)" value="#1 Seed"></td>
</tr>
<tr>
    <td></td>
    <td><input type=text readonly class="team" name="pick1_1" onclick="win(this)" value=""></td>
</tr>
<tr>
    <td><input type=text readonly class="team" name="pick0_2" onclick="win(this)" value="#16 Seed"></td>
</tr>
<tr>
etc.etc......

 

This all works fine. But I now want to have 4 separate quadrants in the bracket (one for Midwest, one for East, one for South and one for West).

 

So in the HTML, I'm going to add an "e" (for East) to the name property for each input element so that those names read "picke1_1" instead of "pick1-1" and this will help me know the picks from which particular quadrant.

 

Therefore, when all four quadrants are added to the HTML, the name properties will all start with either...

 

picke

pickm

picks

pickw

 

instead of only starting with "pick".

 

So now, back up in the Javascript, everywhere you see "pick", I instead need that to essentially say "picke" OR "pickw" OR "picks" OR "pickm" so that the javascript will continue to work when I add the other 3 quadrants with the new varying "name" properties.

 

If this makes any sense, is this doable?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.