note 47505 deleted from language.types.array by tomsommer

From: Date: Thu, 18 Nov 2004 19:41:23 +0000
Subject: note 47505 deleted from language.types.array by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80716@lists.php.net to get a copy of this message
Note Submitter: Ian Winstanley ---- 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>

« previous php.notes (#80716) next »