It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Make selection based on number

Make selection based on number

Postby luiddog on Wed Oct 03, 2007 3:53 pm

I'm trying to build a ncaa bracket page. What I want to do is have the two teams with a score box next to it, after the user inputs the score the script selects the next round winner, and same with the next round.

Example:
Duke 66
Wake Forest 57

Automatically inputs Duke to the next round.

This is what I have so far:

--------------------------------------------------
<script type="text/javascript" language="javascript">
function GetScore()
{
scorea=document.getElementById("scorea");
scoreb=document.getElementById("scoreb");

if (scorea.value > scoreb.value) {
results.value=1;
}
if (scoreb.value > scorea.value) {
results.value=2;
}
}
</script>

Duke:<input name="scorea" type="text" id="scorea" onChange="GetScore()" size="1" maxlength="2">
Wake Forest:<input name="scoreb" type="text" id="scoreb" onChange="GetScore()" size="1" maxlength="2">
--------------------------------------------------

and I can get it to work if the results field is a text field and inputs a number. Ideally, it would populate a drop down or a text field with text. Like if the code below worked, but I'm a js newbie. So obviously it's wrong. But what the finished script needs to do is work in multiple rounds. After the first round there are subsequent rounds based on the winners of the first. So:

--------------------------------------------------
<script type="text/javascript" language="javascript">
function GetScore()
{
scorea=document.getElementById("scorea");
scoreb=document.getElementById("scoreb");
scorec=document.getElementById("scorec");
scored=document.getElementById("scored");
scoree=document.getElementById("scoree");
scoref=document.getElementById("scoref");
if (scorea.value > scoreb.value) {
resultsa.value='Duke';
}
if (scoreb.value > scorea.value) {
resultsa.value='Wake Forest';
}
if (scorec.value > scored.value) {
resultsb.value='UCONN';
}
if (scored.value > scorec.value) {
resultsb.value='BC';
}
}
</script>

Duke:<input name="scorea" type="text" id="scorea" onChange="GetScore()" size="1" maxlength="2">
Wake Forest:<input name="scoreb" type="text" id="scoreb" onChange="GetScore()" size="1" maxlength="2">

UCONN:<input name="scorec" type="text" id="scorec" onChange="GetScore()" size="1" maxlength="2">
BC:<input name="scored" type="text" id="scored" onChange="GetScore()" size="1" maxlength="2">

<select name="resultsa">
<option value="">Winner</option>
<option value="Duke">Duke</option>
<option value="Wake Forest">Wake Forest</option>
</select>
<input name="scoree" type="text" id="scoree" onChange="GetScore()" size="1" maxlength="2">

<select name="resultsb">
<option value="">Winner</option>
<option value="UCONN">UCONN</option>
<option value="BC">BC</option>
</select>
<input name="scoref" type="text" id="scoref" onChange="GetScore()" size="1" maxlength="2">
--------------------------------------------------
Reply With Quote
luiddog
 
Posts: 0
Joined: Wed Oct 03, 2007 3:50 pm

Postby dafunkymunky on Fri Oct 05, 2007 2:53 pm

1....OK how is the second round winner chosen? based on the first round code or does the user hav to input data again?

2...and if the number of players is fixed, then its ok to hard code the no of text boxes, otherwise i advise you to dynamically create text boxes, that is if the user decides how many players, then automatically the javascript creates so many no of boxes and then the evaluation of the results start..

If you can answer these two questions i can help..
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
User avatar
dafunkymunky
100+ Club
 
Posts: 183
Joined: Fri Apr 08, 2005 7:32 am
Location: India


Who is online

Users browsing this forum: No registered users and 5 guests