Say I have a variable number of form fields that can:
a) contain only numbers - if the user tries to enter anything but a number the text is deleted
b) no two fields can contain the same numbers
c) no field can be left empty before the form is submitted

For example, say there are 10 fields (there could be more or less), how would I write script that when the user submits the form, it is checked against every other field (no matter how many there are) and if it is the same then an error message is generated. And if the user tries to submit the form with any empty fields it creates an error message. I know bits and pieces of how to achieve this, I just don't know how to put it together into something that works.

Here is an example I started on:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script type="text/javascript">

function fieldcheck() {


<form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" >
<input type="text" name="test1" maxlength="2" value="1" /><br/>
<input type="text" name="test2" maxlength="2" value="2" /> <br />
<input type="text" name="test3" maxlength="2" value="3" /><br />
<input type="text" name="test4" maxlength="2" value="4" /> <br />
<input type="text" name="test5" maxlength="2" value="5" /><br />
<input type="text" name="test6" maxlength="2" value="6" /><br />
<input type="text" name="test7" maxlength="2" value="7" /><br />
<input type="text" name="test8" maxlength="2" value="8" /><br />
<!-- Could be more or less -->
<input type="image" name="sumbit2" src="update.png" value="TRUE"/>



Thanks in advance,

Take a look at the onmouseup and onchange attributes for the input fields.
Also look at regex (regular expressions) to check the field contents for only numbers.

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.