PDA

View Full Version : Make selection based on number



luiddog
10-03-2007, 03:59 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">
--------------------------------------------------

bers99
10-05-2007, 03:06 PM
+1 i'm need this ;)
http://yourmp3planet.com/crede-in-mine/alb70585/