Jason,

Thanks. That seems to build the javascript string, but unfortunately the form doesn't validate. In other words, if I leave all the checkboxes unchecked the results page still is returned.

Perhaps there is a problem with the javascript? Any ideas?

Albert Padley

On Aug 6, 2004, at 10:02 PM, Jason Paschal wrote:

here's an idea:

above the HTML, you could put something like this [i'm going to use pseudo-code since i don't know how you set it up, but you may have to do the same query twice]:


$counter = 0; loop through records { $id = $row['id']; $counter++; if ($counter > 1) { $jscondition .= " || mainform.ed[" . $id . "].checked"; } else { $jscondition .= "mainform.ed[" . $id . "].checked"; } }

then in ur javascript:

<SCRIPT>
function validate() {
if (!(<?php print $jscondition; ?>)) {


---------------------------------------
http://www.dailymedication.com - Everything you didn't know you needed until you went there and said to yourself, "What did I do before I visited DailyMedication.com?" and another part of you answered, "It does not matter. You are here now."






From: Albert Padley <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: [PHP] Validating Dynamic Checkboxes
Date: Fri, 6 Aug 2004 21:49:40 -0600

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)) {

Any help, pointers, suggestions, etc. will be greatly appreciated.

Thanks.

Albert Padley

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/





-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to