Jump to content

Help With Validating (making what I got repeatable)


jdubwelch

Recommended Posts

I'm making a online march madness bracket.  I need to validate two things: 1) That every field has a value 2) That the current field is a "parent" of the previous two games.

 

There's roughly 60 games that I need to validate.

 

On a smaller scale:  Let's say each field below "A1 - A15" needs to have something it it.  When the user clicks on A1 that value in A1 (which is the team the user thinks is going to win) goes to A9.  And likewise the value of A3 or A4 will go to A10.  Then when they click on A9 or A10 it will put that value in A13, etc. 

 

A1

      A9

A2 

                A13

A3       

      A10

A4

                            A15

A5

      A11

A6

                A14

A7

      A12

A8

 

So I need to validate that the value of A7 is actually in A5 or A6. 

 

Currently I'm doing that by:

function validate_form() {
	if ( document.myForm.winnerA15.value == "" ) {
		alert ( "Please complete the form." );
		return false;
	}
	if ((document.myForm.winner15.value != document.myForm.winnerA13.value) && (document.myForm.winnerA15.value != document.myForm.winnerA14.value)) {	
		alert("Your champion is not in the championship game.");
		return false;
	}

 

Is there a way to make it repeatable?

 

I have 4 brackets: A, B, C, D

Each bracket has 15 "winners"

 

 

 

 

Link to comment
Share on other sites

Okay,  So this is what I got by trial and error.  More error than anything. 

 

It doesn't seem to work.  My page just loads and doesn't do anything.

 

Any ideas?

 

function validate_form() {

	var bracketArray = new Array('A', 'B', 'C', 'D');

	for(var i=0; i<=bracketArray.length-1; i++) {
		var bracket = bracketArray[i];
		for (var j=15; j>=1; --j) {
			document.write('<p>' +  bracket + j + '<br />');
			checkTeamsBefore (bracket, j);
			document.write('</p>');
		}

	}

	return false;


}

function checkTeamsBefore (bracket, game) {

	var gameNum = 16 - game;

	var prevGame1 = game - gameNum;
	var prevGame2 = game - (gameNum + 1);

	if ((document.myForm.winner + game.value != document.myForm.winner + prevGame1.value) && (document.myForm.winner + game.value != document.myForm.winner + prevGame2.value)) {	
		alert("Teams don't match up.");
	} else {
		alert("Teams do match. Game: " + bracket + game);
	}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.