[PHP] Re: Validating Dynamic Checkboxes
Hello, On 08/07/2004 12:49 AM, Albert Padley wrote: I have a php/mysql script that returns a series of records to populate a form. The number of records returned varies from 1 to as many as 100. On the display page, each record has a checkbox to indicate that the record is being edited. This is checked on the results page to know which records to update. The checkbox code is: input type=\checkbox\ name=\ed[{$row['id']}]\ value=\Y\ This part of the system has been working perfectly for weeks. Now I've been asked to add client side validation to make sure at least one of the records (checkboxes) has been checked before sending the data to the results page. (The results page already has working validation code in it.) I've have the following javascript code that should work for my purposes if I can figure out how to dynamically build the javascript code. SCRIPT function validate() { if (!(mainform.ed[0].checked || mainform.ed[1].checked)) { alert('Please check at least one record before submitting this form.'); event.returnValue=false; } } /SCRIPT This is the line I need to build dynamically: if (!(mainform.ed[0].checked || mainform.ed[1].checked)) { It can't be done that way because the brackets have a different meaning in Javascript syntax. You need to quote the whole name. You may want to take a look at the example that comes with this forms generation and validation class that supports the exact same type of validation that you want: http://www.phpclasses.org/formsgeneration -- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Validating Dynamic Checkboxes
On Aug 6, 2004, at 10:39 PM, Manuel Lemos wrote: Hello, On 08/07/2004 12:49 AM, Albert Padley wrote: I have a php/mysql script that returns a series of records to populate a form. The number of records returned varies from 1 to as many as 100. On the display page, each record has a checkbox to indicate that the record is being edited. This is checked on the results page to know which records to update. The checkbox code is: input type=\checkbox\ name=\ed[{$row['id']}]\ value=\Y\ This part of the system has been working perfectly for weeks. Now I've been asked to add client side validation to make sure at least one of the records (checkboxes) has been checked before sending the data to the results page. (The results page already has working validation code in it.) I've have the following javascript code that should work for my purposes if I can figure out how to dynamically build the javascript code. SCRIPT function validate() { if (!(mainform.ed[0].checked || mainform.ed[1].checked)) { alert('Please check at least one record before submitting this form.'); event.returnValue=false; } } /SCRIPT This is the line I need to build dynamically: if (!(mainform.ed[0].checked || mainform.ed[1].checked)) { It can't be done that way because the brackets have a different meaning in Javascript syntax. You need to quote the whole name. You may want to take a look at the example that comes with this forms generation and validation class that supports the exact same type of validation that you want: http://www.phpclasses.org/formsgeneration Hi Manuel, I'm not certain I understand what you mean by quote the whole name. Also, there are a lot of files in the formsgeneration class. Which one has the example you are referring to? Thanks. Albert Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Validating Dynamic Checkboxes
Hello, On 08/07/2004 01:44 AM, Albert Padley wrote: It can't be done that way because the brackets have a different meaning in Javascript syntax. You need to quote the whole name. You may want to take a look at the example that comes with this forms generation and validation class that supports the exact same type of validation that you want: http://www.phpclasses.org/formsgeneration Hi Manuel, I'm not certain I understand what you mean by quote the whole name. The name of the input needs to be quoted (and eventually escaped) and used as an index string. Also, there are a lot of files in the formsgeneration class. Which one has the example you are referring to? The main example ( test_form.php ) has an example of how to validate a group of check boxes making sure that at least one is set. It will do it either on the client side and server side, despite your problem is mostly on the client side Javascript. -- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php