Stateless Form--------- Looking for Script to find highest value from a different form.

Stateless Form--------- Looking for Script to find highest value from a different form.

Hello all,
 
What is a script that will allow me to find the following?
 
1.  If a record does not exist in a form, I need to assign the value of "1" to a field in my stateless form.
 
2.  If a record does exist in a form, I need to increment the MAX value found in the record by 1.
 
What is the easiest and simplest scripts to accomplish this task?
 
Thanks,
Bartley.