Help with basketball bracket please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jimmy Smits

    #1

    Help with basketball bracket please

    Hi
    I have been playing with some JS that I cut from another page. It is a NCAA
    tournament bracket. When the user clicks on the submit button it sends the
    predictions to a db I have created.
    I got all of this to work fine. The problem I have now is that the
    predictions are sent to my DB as numbers for example Kentucky = 0 so anytime
    the user selects Kentucky it sends a zero.
    For the life of me I cant find where in the script I can change this so that
    it submits "kentucky" rather than a zero.

    Here is the code:
    <script language=JavaSc ript>
    <!--

    function InitWindow()
    {document.PickE ntry.reset();}

    IE4 = document.all;

    function oldAlert(mess) {
    newAlert(" Entry Error",mess,3,0 );
    }

    function newAlert(title, mess,icon,mods) {
    (IE4) ? makeMsgBox(titl e,mess,icon,0,0 ,mods) : alert(mess);
    }

    function newConfirm(titl e,mess,icon,def but,mods) {
    if (IE4) {
    icon = (icon==0) ? 0 : 2;
    defbut = (defbut==0) ? 0 : 1;
    retVal = makeMsgBox(titl e,mess,icon,4,d efbut,mods);
    retVal = (retVal==6);
    }
    else {
    retVal = confirm(mess);
    }
    return retVal;
    }

    function newPrompt(title ,mess,def) {
    retVal = (IE4) ? makeInputBox(ti tle,mess,def) : prompt(mess,def );
    if (retVal) {}
    else {retVal = '';}
    return retVal;
    }

    function WriteIt(id, text)
    {if (document.layer s){
    var l = document[id];
    if (!l.ol) {
    var ol = l.ol = new Layer (l.clip.width, l);
    ol.clip.width = l.clip.width;
    ol.clip.height = l.clip.height;
    ol.bgColor = l.bgColor;
    l.visibility = 'hide';
    ol.visibility = 'show';}
    var ol = l.ol;
    out = " ";
    add = "&nbsp;";
    teamtext = "" + text;
    while (teamtext.index Of(out)>-1){
    pos= teamtext.indexO f(out);
    teamtext = "" + (teamtext.subst ring(0, pos) + add +
    teamtext.substr ing((pos + out.length), teamtext.length ));}
    ol.document.ope n();
    ol.document.wri te('<span class="oddrow"> '+teamtext+'</span>');
    ol.document.clo se();
    ol.clip.width=l .clip.width=ol. document.width;
    ol.clip.height= l.clip.height=o l.document.heig ht;}
    else if (document.all || document.getEle mentById) {
    if (document.all)
    document.all[id].innerText = text;
    else {
    var l = document.getEle mentById(id);
    var r = document.create Range();
    r.setStartAfter (l);
    var docFrag = r.createContext ualFragment(tex t);
    while (l.hasChildNode s())
    l.removeChild(l .firstChild);
    l.appendChild(d ocFrag);}
    }
    }

    function PickIt(pickid, teamid)
    {var id="entry"+pick id;
    var currpick = document.PickEn try.elements["PICK"+pick id].value;
    if (pickid > 32){
    teamid = document.PickEn try.elements["PICK"+team id].value;
    if (teamid == 64) {return;}
    teamid++;}
    if (currpick == teamid-1){return;};
    var text=document.P ickEntry.elemen ts["TEAM"+team id].value;
    document.PickEn try.elements["PICK"+pick id].value = teamid-1;
    WriteIt(id, text);
    var nextround = pickid;
    while (nextround != 63){
    var nextroundpick =
    document.PickEn try.elements["PICK"+next game[nextround]].value;
    if (nextroundpick != 64){
    if (nextroundpick == currpick){
    if (nextroundpick != teamid-1){
    document.PickEn try.elements["PICK"+next game[nextround]].value = teamid-1;
    WriteIt("entry" +nextgame[nextround],text);
    }
    }
    }
    nextround = nextgame[nextround];}
    }

    var spacer='&nbsp';
    if(document.lay ers){
    for(counter=2; counter <= 15; counter++)
    {spacer=spacer+ '&nbsp;'}
    origWidth=inner Width;
    origHeight=inne rHeight;
    onresize=functi on(){
    if(innerWidth!= origWidth||inne rHeight!=origHe ight)
    location.reload ()}
    }

    var nextgame = new Array(62);
    nextgame[1] = nextgame[2] = 33;
    nextgame[3] = nextgame[4] = 34;
    nextgame[5] = nextgame[6] = 35;
    nextgame[7] = nextgame[8] = 36;
    nextgame[9] = nextgame[10] = 37;
    nextgame[11] = nextgame[12] = 38;
    nextgame[13] = nextgame[14] = 39;
    nextgame[15] = nextgame[16] = 40;
    nextgame[17] = nextgame[18] = 41;
    nextgame[19] = nextgame[20] = 42;
    nextgame[21] = nextgame[22] = 43;
    nextgame[23] = nextgame[24] = 44;
    nextgame[25] = nextgame[26] = 45;
    nextgame[27] = nextgame[28] = 46;
    nextgame[29] = nextgame[30] = 47;
    nextgame[31] = nextgame[32] = 48;
    nextgame[33] = nextgame[34] = 49;
    nextgame[35] = nextgame[36] = 50;
    nextgame[37] = nextgame[38] = 51;
    nextgame[39] = nextgame[40] = 52;
    nextgame[41] = nextgame[42] = 53;
    nextgame[43] = nextgame[44] = 54;
    nextgame[45] = nextgame[46] = 55;
    nextgame[47] = nextgame[48] = 56;
    nextgame[49] = nextgame[50] = 57;
    nextgame[51] = nextgame[52] = 58;
    nextgame[53] = nextgame[54] = 59;
    nextgame[55] = nextgame[56] = 60;
    nextgame[57] = nextgame[58] = 61;
    nextgame[59] = nextgame[60] = 62;
    nextgame[61] = nextgame[62] = 63;

    function PlayerIDCheck()
    { var form = self.document.f orms["PickEntry"];
    if(form.PLAYERI D.value=="")
    { oldAlert(" You must enter: Name Last,First.");
    form.PLAYERID.f ocus();
    return false;}
    else { return true;}}

    function PlayerInfo3Chec k()
    { var form = self.document.f orms["PickEntry"];
    if(form.PLAYERI NFO3.value=="")
    { oldAlert(" You must enter: E-Mail Address.");
    form.PLAYERINFO 3.focus();
    return false;}
    else { return true;}}

    function PlayerInfo3Mail Check()
    { var form = self.document.f orms["PickEntry"];
    if ((form.PLAYERIN FO3.value == " ") ||(form.PLAYERI NFO3.value.inde xOf ('@',
    0) == -1) ||(form.PLAYERI NFO3.value.inde xOf ('.', 0) == -1))
    { oldAlert(" You must enter a valid e-mail address for the E-Mail
    Address.");
    form.PLAYERINFO 3.focus();
    return false;}
    else { return true;}
    }

    function TieBreakerPoint sCheck()
    { var form = self.document.f orms["PickEntry"];
    if(form.TIEBREA KER.value=="")
    { oldAlert(" You must enter: Tie Breaker Points.");
    form.TIEBREAKER .focus();
    return false;}
    else { return true;}}

    function VerifyPick()
    {var form = self.document.f orms["PickEntry"];
    var NoPickMade = 0;
    for(counter=1; counter <= 63; counter++)
    { var GamePick = document.PickEn try.elements["PICK"+coun ter].value;
    if (GamePick == 64) {NoPickMade++;} }
    if(NoPickMade > 0){ oldAlert(" You must enter a selection for every game.");
    return false;}
    else { return true;}}

    function VerifyPage() {
    if (! PlayerIDCheck() ) { return false;}
    if (! PlayerInfo3Chec k()) { return false;}
    if (! PlayerInfo3Mail Check()) { return false;}
    if (! VerifyPick()) { return false;}
    if (! TieBreakerPoint sCheck()) { return false;}
    return true;}

    // -->
    </script>

    <script language=VBScri pt>
    <!--

    Function makeMsgBox(titl e, mess, icon, buts, defbut, mods)
    butVal = buts + (icon * 16) + (defbut * 256) + (mods * 4096)
    makeMsgBox = MsgBox(mess, butVal, title)
    End Function

    // -->
    </script>

    Thanks for reading




  • Spats30

    #2
    Re: Help with basketball bracket please

    This code doesn't tell us much, except that "Picks" are referred to as
    numbers. I would assume that these numbers are passed from probably
    HTML <select> menu drop downs. As such, you probably have attritubutes
    that match something like <option value="0">Kentu cky</option>

    In the end, it is whatever HTML form value that is posted to your form
    handler that is inserted into the database, not what the javascript
    does, (unless the JS changes the HTML form value.)

    On your form handler, you might have to make a teamID mapping to make a
    conversion before inserting into your database.

    Comment

    • RobG

      #3
      Re: Help with basketball bracket please

      Jimmy Smits wrote:[color=blue]
      > Hi
      > I have been playing with some JS that I cut from another page. It is a NCAA
      > tournament bracket. When the user clicks on the submit button it sends the
      > predictions to a db I have created.
      > I got all of this to work fine. The problem I have now is that the[/color]

      I'm guessing that your script works only in IE and maybe older
      Netscape. It needs some serious cleaning up.
      [color=blue]
      > predictions are sent to my DB as numbers for example Kentucky = 0 so anytime
      > the user selects Kentucky it sends a zero.
      > For the life of me I cant find where in the script I can change this so that
      > it submits "kentucky" rather than a zero.[/color]
      [...]

      I'll presume that the selection is made by an option within a
      select element. If so, look at this line:
      [color=blue]
      > var currpick = document.PickEn try.elements["PICK"+pick id].value;[/color]

      The select (probably) has a name of PICK plus a number. It then
      has a value and some text, the HTML probably looks something
      like:

      <option name="PICK0" value="0" ...>Kentucky</option>

      The line above selects the value of the option "0". You want
      the text "Kentucky". So change the line to:

      var currpick = document.PickEn try.elements["PICK"+pick id].text;


      In regard to cleaning up the script, consider the following:
      [color=blue]
      > IE4 = document.all;
      >
      > function oldAlert(mess) {
      > newAlert(" Entry Error",mess,3,0 );
      > }
      >
      > function newAlert(title, mess,icon,mods) {
      > (IE4) ? makeMsgBox(titl e,mess,icon,0,0 ,mods) : alert(mess);
      > }[/color]

      Any browser that your script thinks supports "document.a ll" will
      be classified as "IE4". Your script will then attempt to call
      "makeMsgBox ()", which will not work on all browsers that support
      document.all, nor will it work on any platform that does not
      support VBscript (since makeMsgBox() is defined later as a
      VBscript function).

      There are likely numerous other examples in the script.

      Essentially, only visitors running IE on Windows will be able
      to use this script.



      --
      Rob

      Comment

      • RobG

        #4
        Re: Help with basketball bracket please

        Spats30 wrote:[color=blue]
        > This code doesn't tell us much, except that "Picks" are referred to as
        > numbers. I would assume that these numbers are passed from probably
        > HTML <select> menu drop downs. As such, you probably have attritubutes
        > that match something like <option value="0">Kentu cky</option>
        >
        > In the end, it is whatever HTML form value that is posted to your form
        > handler that is inserted into the database, not what the javascript
        > does, (unless the JS changes the HTML form value.)
        >
        > On your form handler, you might have to make a teamID mapping to make a
        > conversion before inserting into your database.[/color]

        Alternatively, simply remove the value from the option. If no
        value is given, the contents of the option are submitted.
        Changing your line above to:

        <option>Kentuck y</option>

        means that "Kentucky" will be submitted.

        From the HTML 4.01 spec:

        OPTION Attribute definitions
        ...
        value = cdata [CS]
        This attribute specifies the initial value of the control. If
        this attribute is not set, the initial value is set to the
        contents of the OPTION element.

        <URL:http://www.w3.org/TR/html4/interact/forms.html#h-17.6>


        --
        Rob

        Comment

        • Jimmy Smits

          #5
          Re: Help with basketball bracket please


          "RobG" <rgqld@iinet.ne t.auau> wrote in message
          news:l1SOd.489$ Ud4.38853@news. optus.net.au...[color=blue]
          > Jimmy Smits wrote:[color=green]
          > > Hi
          > > I have been playing with some JS that I cut from another page. It is a[/color][/color]
          NCAA[color=blue][color=green]
          > > tournament bracket. When the user clicks on the submit button it sends[/color][/color]
          the[color=blue][color=green]
          > > predictions to a db I have created.
          > > I got all of this to work fine. The problem I have now is that the[/color]
          >
          > I'm guessing that your script works only in IE and maybe older
          > Netscape. It needs some serious cleaning up.
          >[color=green]
          > > predictions are sent to my DB as numbers for example Kentucky = 0 so[/color][/color]
          anytime[color=blue][color=green]
          > > the user selects Kentucky it sends a zero.
          > > For the life of me I cant find where in the script I can change this so[/color][/color]
          that[color=blue][color=green]
          > > it submits "kentucky" rather than a zero.[/color]
          > [...]
          >
          > I'll presume that the selection is made by an option within a
          > select element. If so, look at this line:
          >[color=green]
          > > var currpick = document.PickEn try.elements["PICK"+pick id].value;[/color]
          >
          > The select (probably) has a name of PICK plus a number. It then
          > has a value and some text, the HTML probably looks something
          > like:
          >
          > <option name="PICK0" value="0" ...>Kentucky</option>
          >
          > The line above selects the value of the option "0". You want
          > the text "Kentucky". So change the line to:
          >
          > var currpick = document.PickEn try.elements["PICK"+pick id].text;
          >
          >
          > In regard to cleaning up the script, consider the following:
          >[color=green]
          > > IE4 = document.all;
          > >
          > > function oldAlert(mess) {
          > > newAlert(" Entry Error",mess,3,0 );
          > > }
          > >
          > > function newAlert(title, mess,icon,mods) {
          > > (IE4) ? makeMsgBox(titl e,mess,icon,0,0 ,mods) : alert(mess);
          > > }[/color]
          >
          > Any browser that your script thinks supports "document.a ll" will
          > be classified as "IE4". Your script will then attempt to call
          > "makeMsgBox ()", which will not work on all browsers that support
          > document.all, nor will it work on any platform that does not
          > support VBscript (since makeMsgBox() is defined later as a
          > VBscript function).
          >
          > There are likely numerous other examples in the script.
          >
          > Essentially, only visitors running IE on Windows will be able
          > to use this script.
          >
          >
          >
          > --
          > Rob[/color]

          Thanks so much for all your suggestions. I am going to poke around today and
          see if I can make any of these ideas work. I will keep you posted!

          Thanks Again!


          Comment

          • Jimmy Smits

            #6
            Re: Help with basketball bracket please


            "RobG" <rgqld@iinet.ne t.auau> wrote in message
            news:u9SOd.494$ Ud4.38869@news. optus.net.au...[color=blue]
            > Spats30 wrote:[color=green]
            > > This code doesn't tell us much, except that "Picks" are referred to as
            > > numbers. I would assume that these numbers are passed from probably
            > > HTML <select> menu drop downs. As such, you probably have attritubutes
            > > that match something like <option value="0">Kentu cky</option>
            > >
            > > In the end, it is whatever HTML form value that is posted to your form
            > > handler that is inserted into the database, not what the javascript
            > > does, (unless the JS changes the HTML form value.)
            > >
            > > On your form handler, you might have to make a teamID mapping to make a
            > > conversion before inserting into your database.[/color]
            >
            > Alternatively, simply remove the value from the option. If no
            > value is given, the contents of the option are submitted.
            > Changing your line above to:
            >
            > <option>Kentuck y</option>
            >
            > means that "Kentucky" will be submitted.
            >
            > From the HTML 4.01 spec:
            >
            > OPTION Attribute definitions
            > ...
            > value = cdata [CS]
            > This attribute specifies the initial value of the control. If
            > this attribute is not set, the initial value is set to the
            > contents of the OPTION element.
            >
            > <URL:http://www.w3.org/TR/html4/interact/forms.html#h-17.6>
            >
            >
            > --
            > Rob[/color]

            I am have sooo much to learn, I am understanding what you are saying. In
            both of your posts. And there is alot of excess code in there that I am
            trying to clean up because it doesnt apply to my site or to what I am doing.

            In reference to your other post when I tried to change

            var currpick = document.PickEn try.elements["PICK"+pick id].value;

            to

            var currpick = document.PickEn try.elements["PICK"+pick id].text;

            It still gives me numbers in the DB. I am trying to follow the values of the
            teams through the code but I get lost.

            There are many Hidden inputs. The tournament has 64 winners. so there are 64
            of these all with a value of 64.
            <input type=hidden name=PICK1 value=64>

            And this line is also in there along with others - one for each team of
            course:
            <input type=hidden name=TEAM1 value="Kentucky ">
            Which before I ever posted here I thought would give me a value of 1 for
            Kentucky - however Kentucky comes as "0"

            Are these values not being submitted?

            Thanks again for reading.



            Comment

            • Jimmy Smits

              #7
              Re: Help with basketball bracket please


              Anyone with any thoughts?


              "Jimmy Smits" <jimmys@hotmail .com> wrote in message
              news:4u7Pd.6902 $Sx6.1069385@re ad2.cgocable.ne t...[color=blue]
              >
              > "RobG" <rgqld@iinet.ne t.auau> wrote in message
              > news:u9SOd.494$ Ud4.38869@news. optus.net.au...[color=green]
              > > Spats30 wrote:[color=darkred]
              > > > This code doesn't tell us much, except that "Picks" are referred to as
              > > > numbers. I would assume that these numbers are passed from probably
              > > > HTML <select> menu drop downs. As such, you probably have[/color][/color][/color]
              attritubutes[color=blue][color=green][color=darkred]
              > > > that match something like <option value="0">Kentu cky</option>
              > > >
              > > > In the end, it is whatever HTML form value that is posted to your form
              > > > handler that is inserted into the database, not what the javascript
              > > > does, (unless the JS changes the HTML form value.)
              > > >
              > > > On your form handler, you might have to make a teamID mapping to make[/color][/color][/color]
              a[color=blue][color=green][color=darkred]
              > > > conversion before inserting into your database.[/color]
              > >
              > > Alternatively, simply remove the value from the option. If no
              > > value is given, the contents of the option are submitted.
              > > Changing your line above to:
              > >
              > > <option>Kentuck y</option>
              > >
              > > means that "Kentucky" will be submitted.
              > >
              > > From the HTML 4.01 spec:
              > >
              > > OPTION Attribute definitions
              > > ...
              > > value = cdata [CS]
              > > This attribute specifies the initial value of the control. If
              > > this attribute is not set, the initial value is set to the
              > > contents of the OPTION element.
              > >
              > > <URL:http://www.w3.org/TR/html4/interact/forms.html#h-17.6>
              > >
              > >
              > > --
              > > Rob[/color]
              >
              > I am have sooo much to learn, I am understanding what you are saying. In
              > both of your posts. And there is alot of excess code in there that I am
              > trying to clean up because it doesnt apply to my site or to what I am[/color]
              doing.[color=blue]
              >
              > In reference to your other post when I tried to change
              >
              > var currpick = document.PickEn try.elements["PICK"+pick id].value;
              >
              > to
              >
              > var currpick = document.PickEn try.elements["PICK"+pick id].text;
              >
              > It still gives me numbers in the DB. I am trying to follow the values of[/color]
              the[color=blue]
              > teams through the code but I get lost.
              >
              > There are many Hidden inputs. The tournament has 64 winners. so there are[/color]
              64[color=blue]
              > of these all with a value of 64.
              > <input type=hidden name=PICK1 value=64>
              >
              > And this line is also in there along with others - one for each team of
              > course:
              > <input type=hidden name=TEAM1 value="Kentucky ">
              > Which before I ever posted here I thought would give me a value of 1 for
              > Kentucky - however Kentucky comes as "0"
              >
              > Are these values not being submitted?
              >
              > Thanks again for reading.
              >
              >
              >[/color]


              Comment

              • RobG

                #8
                Re: Help with basketball bracket please

                Jimmy Smits wrote:[color=blue]
                > Anyone with any thoughts?
                >[/color]
                [...]

                Really need to see the entire page to work out what is
                happening - I think that is beyond the scope of a news group.
                If you want to post a URL, perhaps we can take it from there.

                There are slabs of JS that very likely could be optimised, this
                group can help with specific issues, but trying to fix 200 lines
                of code without the HTML or any idea of what it is actually (or
                supposed to be) doing is not very productive.

                For example, the 30 lines that define the nextgame array could
                be generated by:

                var nextgame = [];
                for (var i=1; i<63; i+=2){
                nextgame[i] = nextgame[i+1] = Math.floor(i/2)+33;
                }

                If indeed an array is needed at all - it is quite possible that
                the value of nextgame can be calculated when required, the
                values in the array are not altered by the code you provided.

                Similarly, all the IE specific stuff should be replaced with
                simpler functions that are suitable for all browsers.


                Reply via email if you wish (delete last "au").


                --
                Rob

                Comment

                • Dr John Stockton

                  #9
                  Re: Help with basketball bracket please

                  JRS: In article <cUgQd.539$Ud4. 43204@news.optu s.net.au>, dated Tue, 15
                  Feb 2005 06:45:28, seen in news:comp.lang. javascript, RobG
                  <rgqld@iinet.ne t.auau> posted :[color=blue]
                  >
                  > For example, the 30 lines that define the nextgame array could
                  > be generated by:
                  >
                  > var nextgame = [];
                  > for (var i=1; i<63; i+=2){
                  > nextgame[i] = nextgame[i+1] = Math.floor(i/2)+33;
                  > }[/color]

                  Or even by

                  var nextgame = []
                  for (var i=1, j=33; i<63; i+=2) nextgame[i] = nextgame[i+1] = j++

                  --
                  © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                  <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                  <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                  <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                  Comment

                  Working...