Loop a form with constantly changing values

Loop a form with constantly changing values

Hi,
 
I want to build a php/ajax script that does the following. I don't have any experience with java or ajax. If you can point me in the right direction, I am very grateful.
 
I am mainly interested in learning how I should use ajax to execute the following.
 
The script should work along these lines:
 
$var1 = 'x';
$var2 = 'y';
$var3 = 'z';
 
if(thescript is posted for the first time || script should be reload) {
 
ajax: post vars to: input.php, do something
get output(random number based on input from $vars) from input (ie $number1 and $number2}
 
<div=myform>
 
echo $number1 echo $number2 
echo <inputfield>
</div=myform>
<div message>
 
<div error>
error message
</div error>
 
<div correct>
correct
<div correct>
 
ajax.onclick.post inputfield to output.php 
 
if (isempty(inputfield) then display $message under <input field>
if(!isempty(inputfield) -->2 options 
        if(error) then display <div error>;
        if(no-error)then display for 0,2 seconds <div correct> AND after that the form should be reloaded by running input.php again. So the user can start with a fresh form.