galvin Posted March 23, 2010 Share Posted March 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/196191-help-with-or-in-javascript/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.