copia e incolla
codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Author" content="Fabrizio Calderan, http://www.fabriziocalderan.it/" /> <title>Valori unici</title> </head> <body> <script> function check(f) { var namePattern = /^bpt_/; var nameFields = {}; var fields = f.getElementsByTagName('input'); for (var i=0; i<fields.length; i++) { if (namePattern.test(fields[i].name)){ if (fields[i].value in nameFields) { alert([fields[i].value, ' è un valore ripetuto.'].join(' ')); return false; } nameFields[fields[i].value] = fields[i].name; } } return true; } </script> </body> <form action="#" onsubmit="return check(this)"> <input type="text" name="bpt_1" value="10"> <input type="text" name="bpt_2" value="231"> <input type="text" name="bpt_3" value="76"> <input type="text" name="bpt_4" value="19"> <input type="text" name="bpt_5" value="10"> <input type="submit" /> </html>

Rispondi quotando