note 20382 added to language.types.array
| From: | ian at vplex dot com | Date: | Tue, 02 Apr 2002 07:16:54 +0000 |
| Subject: | note 20382 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28490@lists.php.net to get a copy of this message | ||
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>
--
http://www.php.net/manual/en/language.types.array.php
http://master.php.net/manage/user-notes.php?action=edit+20382
http://master.php.net/manage/user-notes.php?action=delete+20382
http://master.php.net/manage/user-notes.php?action=reject+20382