note 47505 added to language.types.array

From: Date: Thu, 18 Nov 2004 15:00:55 +0000
Subject: note 47505 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-80697@lists.php.net to get a copy of this message
A way to validate or process form fields with [] in them using JavaScript is to use the notation: - document.form('form_field_name[]').value; In this way the JavaScript engine will not mistake the '[]' as signifying a form field that is part of set in the HTML document and report an empty or non-numeric indices error. Example: <script> function checkForm(frm) { var Msg = ''; if (frm('contact[name]').value == '') { Msg += 'Please enter your name\n'; } if (frm('contact[house]').value == '') { Msg += 'Please enter your house\n'; } if (frm('contact[street]').value == '') { Msg += 'Please enter your street\n'; } if (Msg) { alert(Msg); return false; } else { return f; } } </script> <form onsubmit="return checkForm(this); return false"> <input type="text" name="contact[name]"> <input type="text" name="contact[house]"> <input type="text" name="contact[street]"> <input type="submit" value="Submit"> </form> ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47505 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47505&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47505&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47505&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47505&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47505&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47505&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47505&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80697) next »