Help with basketball bracket please

J

Jimmy Smits

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=JavaScript>
<!--

function InitWindow()
{document.PickEntry.reset();}

IE4 = document.all;

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

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

function newConfirm(title,mess,icon,defbut,mods) {
if (IE4) {
icon = (icon==0) ? 0 : 2;
defbut = (defbut==0) ? 0 : 1;
retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
retVal = (retVal==6);
}
else {
retVal = confirm(mess);
}
return retVal;
}

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

function WriteIt(id, text)
{if (document.layers){
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.indexOf(out)>-1){
pos= teamtext.indexOf(out);
teamtext = "" + (teamtext.substring(0, pos) + add +
teamtext.substring((pos + out.length), teamtext.length));}
ol.document.open();
ol.document.write('<span class="oddrow">'+teamtext+'</span>');
ol.document.close();
ol.clip.width=l.clip.width=ol.document.width;
ol.clip.height=l.clip.height=ol.document.height;}
else if (document.all || document.getElementById) {
if (document.all)
document.all[id].innerText = text;
else {
var l = document.getElementById(id);
var r = document.createRange();
r.setStartAfter(l);
var docFrag = r.createContextualFragment(text);
while (l.hasChildNodes())
l.removeChild(l.firstChild);
l.appendChild(docFrag);}
}
}

function PickIt(pickid, teamid)
{var id="entry"+pickid;
var currpick = document.PickEntry.elements["PICK"+pickid].value;
if (pickid > 32){
teamid = document.PickEntry.elements["PICK"+teamid].value;
if (teamid == 64) {return;}
teamid++;}
if (currpick == teamid-1){return;};
var text=document.PickEntry.elements["TEAM"+teamid].value;
document.PickEntry.elements["PICK"+pickid].value = teamid-1;
WriteIt(id, text);
var nextround = pickid;
while (nextround != 63){
var nextroundpick =
document.PickEntry.elements["PICK"+nextgame[nextround]].value;
if (nextroundpick != 64){
if (nextroundpick == currpick){
if (nextroundpick != teamid-1){
document.PickEntry.elements["PICK"+nextgame[nextround]].value = teamid-1;
WriteIt("entry"+nextgame[nextround],text);
}
}
}
nextround = nextgame[nextround];}
}

var spacer='&nbsp';
if(document.layers){
for(counter=2; counter <= 15; counter++)
{spacer=spacer+'&nbsp;'}
origWidth=innerWidth;
origHeight=innerHeight;
onresize=function(){
if(innerWidth!=origWidth||innerHeight!=origHeight)
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.forms["PickEntry"];
if(form.PLAYERID.value=="")
{ oldAlert(" You must enter: Name Last,First.");
form.PLAYERID.focus();
return false;}
else { return true;}}

function PlayerInfo3Check()
{ var form = self.document.forms["PickEntry"];
if(form.PLAYERINFO3.value=="")
{ oldAlert(" You must enter: E-Mail Address.");
form.PLAYERINFO3.focus();
return false;}
else { return true;}}

function PlayerInfo3MailCheck()
{ var form = self.document.forms["PickEntry"];
if ((form.PLAYERINFO3.value == " ") ||(form.PLAYERINFO3.value.indexOf ('@',
0) == -1) ||(form.PLAYERINFO3.value.indexOf ('.', 0) == -1))
{ oldAlert(" You must enter a valid e-mail address for the E-Mail
Address.");
form.PLAYERINFO3.focus();
return false;}
else { return true;}
}

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

function VerifyPick()
{var form = self.document.forms["PickEntry"];
var NoPickMade = 0;
for(counter=1; counter <= 63; counter++)
{ var GamePick = document.PickEntry.elements["PICK"+counter].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 (! PlayerInfo3Check()) { return false;}
if (! PlayerInfo3MailCheck()) { return false;}
if (! VerifyPick()) { return false;}
if (! TieBreakerPointsCheck()) { return false;}
return true;}

// -->
</script>

<script language=VBScript>
<!--

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

// -->
</script>

Thanks for reading
 
S

Spats30

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">Kentucky</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.
 
R

RobG

Jimmy said:
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

I'm guessing that your script works only in IE and maybe older
Netscape. It needs some serious cleaning up.
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.
[...]

I'll presume that the selection is made by an option within a
select element. If so, look at this line:
var currpick = document.PickEntry.elements["PICK"+pickid].value;

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.PickEntry.elements["PICK"+pickid].text;


In regard to cleaning up the script, consider the following:
IE4 = document.all;

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

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

Any browser that your script thinks supports "document.all" 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.
 
R

RobG

Spats30 said:
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">Kentucky</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.

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>Kentucky</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>
 
J

Jimmy Smits

RobG said:
Jimmy said:
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

I'm guessing that your script works only in IE and maybe older
Netscape. It needs some serious cleaning up.
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.
[...]

I'll presume that the selection is made by an option within a
select element. If so, look at this line:
var currpick = document.PickEntry.elements["PICK"+pickid].value;

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.PickEntry.elements["PICK"+pickid].text;


In regard to cleaning up the script, consider the following:
IE4 = document.all;

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

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

Any browser that your script thinks supports "document.all" 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.

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!
 
J

Jimmy Smits

RobG said:
Spats30 said:
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">Kentucky</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.

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>Kentucky</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>

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.PickEntry.elements["PICK"+pickid].value;

to

var currpick = document.PickEntry.elements["PICK"+pickid].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.
 
J

Jimmy Smits

Anyone with any thoughts?


Jimmy Smits said:
RobG said:
Spats30 said:
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">Kentucky</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.

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>Kentucky</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>

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.PickEntry.elements["PICK"+pickid].value;

to

var currpick = document.PickEntry.elements["PICK"+pickid].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.
 
R

RobG

Jimmy said:
Anyone with any thoughts?
[...]

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 = 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").
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 15
Feb 2005 06:45:28, seen in RobG
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 = nextgame[i+1] = Math.floor(i/2)+33;
}


Or even by

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top