I can't figure out how to validate that no duplicate numbers have been entered, and when they enter a duplicate number it should alert them that they can't do that. Can someone please help me out?

<style type="text/css">
     body {text-align:center; background-color:#151B8D; color:white}
     p.intro {text-align:center; font-size:24pt}
     h1 {font-size:30pt}
  </style>

  <script type="text/javascript">

  function enterValue(f)
{
    var n=parseInt(f.number.value)

   if(n < 1 || n > 9)
   {
   alert("Number must be between 1-9")
   }
   else
   {
   f.elements[f.boxValue.value].value=f.number.value
   }
}

  </script>
 </head>


  <h1>Do you want to play with...</h1>
  <p class="intro">My Suduko Box?</p>

  <form name="matrixBox" id="matrixBox">
 <input type="reset" name="reset" value="Reset" style="background-color:#3BB9FF; color:#15317E;
   border-color:#151B8D; font-size:12pt"><br/><br/>

   <table align="center">
    <tr>
     <td> <input type="text" name="r1c1" size="1"> </td>
     <td> <input type="text" name="r1c2" size="1"> </td>
     <td> <input type="text" name="r1c3" size="1"> </td>

    </tr>
    <tr>
     <td> <input type="text" name="r2c1" size="1"> </td>
     <td> <input type="text" name="r2c2" size="1"> </td>
     <td> <input type="text" name="r2c3" size="1"> </td>
    </tr>

    <tr>
     <td> <input type="text" name="r3c1" size="1"> </td>
     <td> <input type="text" name="r3c2" size="1"> </td>
     <td> <input type="text" name="r3c3" size="1"> </td>
    </tr>
   </table>

   <br/>
   Value: <input type="text" name="number" size="1">
   <br/><br/>
   Box Number: <input type="text" name="boxValue"  size="1">
   <br><br/>

   <input type="button" name="enterVal" value="Enter Value" style="background-color:#3BB9FF; color:#15317E;
   border-color:#151B8D; font-size:12pt" onclick="enterValue(document.matrixBox)">
<!-Why can't I put the reset button here?  If I do it moves the value entered to the next box
instead of the box it was suppose to go inside the matrix->
  </form>
 </body>

</html>
<style type="text/css">
     body {text-align:center; background-color:#151B8D; color:white}
     .intro {text-align:center; font-size:24pt}
     h1 {font-size:30pt}
	 .buttons {background-color:#3BB9FF; color:#15317E; border-color:#151B8D; font-size:12pt}
</style>

<script type="text/javascript">

function enterValue( f )
{
	if( f.ValueField.value.match( /^[1-9]$/ ) )
	{
		if( f.BoxNumber.value.match( /^[1-9]$/ ) )
		{
			var duplicates = false;
			
			for( var i = 0; i < 9 && ! duplicates; i++ )
				if( f.elements[ i ].value == f.ValueField.value )
					duplicates = true;
		
			if( duplicates )
			{
				alert( "The Value you entered must not be already in the table!" );
				f.ValueField.focus();
				f.ValueField.select();
			}
			else
			{
				f.elements[ f.BoxNumber.value - 1 ].value = f.ValueField.value;
							// In JavaScript, indexes start at 0
			}
		}
		else
		{
			// Not-number in Box Number field
			alert( "Box number must be 1 to 9" );
			f.BoxNumber.focus();
			f.BoxNumber.select();
		}
	}
	else
	{
		// Not-number in ValueField field
		alert( "Value must be between 1 and 9" );
		f.ValueField.focus();
		f.ValueField.select();
	}
}

</script>

<h1>Do you want to play with...</h1>
<p class=intro>My Suduko Box?</p>

<form name=matrixBox>
 
   <table align=center>
    <tr>
     <td> <input name=r1c1 size=1 maxlength=1> </td>
     <td> <input name=r1c2 size=1 maxlength=1> </td>
     <td> <input name=r1c3 size=1 maxlength=1> </td>
    </tr>
    <tr>
     <td> <input name=r2c1 size=1 maxlength=1> </td>
     <td> <input name=r2c2 size=1 maxlength=1> </td>
     <td> <input name=r2c3 size=1 maxlength=1> </td>
    </tr>
    <tr>
     <td> <input name=r3c1 size=1 maxlength=1> </td>
     <td> <input name=r3c2 size=1 maxlength=1> </td>
     <td> <input name=r3c3 size=1 maxlength=1> </td>
    </tr>
   </table>

   <p>Value: <input name=ValueField size=1 maxlength=1></p>
   <p>Box Number: <input name=BoxNumber size=1 maxlength=1></p>

   <input type=button name=enterVal value="Enter Value" class=buttons onclick="enterValue(document.matrixBox)">

   <input type=reset name=reset value=Reset class=buttons>

</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.