note 20382 deleted from language.types.array by curt

From: Date: Tue, 06 Jul 2004 02:21:09 +0000
Subject: note 20382 deleted from language.types.array by curt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72646@lists.php.net to get a copy of this message
Note Submitter: ian@vplex.com ---- PHP Arrays and Javascript form checking. Problem: how to use javascript to check a form with MyArray[] form elements Solution: Here is "one" way to solve javascript form checking with MyArray[]type names. Have only checked this with IE5+. It cleverly highlights the <p id=num> html element. This could work with input, span, div etc... This javascript is a modification of some clever code I found off some unamed(?) website. I was really tired, got a copy and went to bed. If you are the javascripts original author, please claim the original base code. <HTML> <HEAD> <TITLE>Dude</TITLE> <script language="JavaScript"> <!-- function check() { var max = document.forms[0].length-1; var retval = true; //alert("checking..."+max+" inputs."); for (i = 0; i < max; i++) { //alert(i+","+document.forms[0][i].value); if (document.forms[0][i].value == '') { //alert(i+" is empty"); document.all["l"+i].style.border = "1px #FF0000 solid"; retval = false; } else { //alert(i+" is not empty"); document.all["l"+i].style.border = "1px #00FF00 solid"; } } if( retval == false ) { alert("Missing Required fields. Missing fields are highlighted in red."); } else { alert("All fields correctly filled out."); // document.iform.submit(); // form is correctly filled out } return retval; } function warn() { if (document.sub.name.value == '') { document.all["light"].style.border = "5px #FF0000 solid"; } } //--> </script> </HEAD> <BODY> <form name="iform" action="some.php"> <p id=l0>Name #1 <input type="text" name="fname[]"> </p> <p id=l1>Name #2 <input type="text" name="fname[]"> </p> <p id=l2>Name #3 <input type="text" name="fname[]"> </p> <p id=l3>Email <input type="text" name="email"> </p> <p> <!-- NOT a submit button. check() will submit the form if passed all checks --> <input type="button" value="Proceed" onclick="check();"> </p> </form>

« previous php.notes (#72646) next »