the js code you sent back failed to reflect any of the significant changes i suggested.
this is what you put:
<SCRIPT language="JavaScript">
function validate() {
if (!(<?php print $jscondition; ?>)) {
alert('Please check at least one edit checkbox before submitting this form.');
return false;
}
}
</SCRIPT>
but that cannot work. you have it so that an alert will trigger if an item is checked, but that is when you want the form to be submitted, and an alert to be triggered otherwise.
first, make sure that your submit button is not an actual submit button, but a regular button that triggers an onClick event, like thus:
<input type='button' onClick='validate()' name='submit' value='Submit'>
then have ur js function work like this: (i may not have coded everything exactly as you needed it, only made it as a model, you'll have to extract the logic and modify it for your needs):
<SCRIPT language="JavaScript"> function validate() { if (!(<?php print $jscondition; ?>)) { document.getElementById('mainform').submit(); } else { alert("Please check at least one item."); } } </SCRIPT>
i tested a simple model locally and it worked fine. if you wish to continue this thread, i'll be glad to assist, but let's keep it out of the mailing list until we hit on something that is directly related to PHP.
good luck, j
note: netscape doesn't always work right with JS, sometimes working contrary to the very language they invented. i tested the code with myIE2.
---------------------------------------
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: Re: [PHP] Validating Dynamic Checkboxes Date: Sat, 7 Aug 2004 00:25:38 -0600
Jason,
You lost me on this go around. I don't understand how we got from the following function to your new verson:
//loop through records
$id = $row['id'];
$counter++;
if ($counter > 1) {
$jscondition .= " || document.getElementById('ed" . $id . "').checked";
} else {
$jscondition .= "document.getElementById('ed" . $id . "').checked";
}
}
?>
<SCRIPT language="JavaScript">
function validate() {
if (!(<?php print $jscondition; ?>)) {
alert('Please check at least one edit checkbox before submitting this form.');
return false;
}
}
</SCRIPT>
Remember that the above works insofar as it throws up the javascript alert, but then submits the form anyway. I don't see how your new function incorporates the loop to build $jscondition.
Thanks for any further input. I think I need to get some sleep.
Albert Padley
On Aug 6, 2004, at 11:39 PM, Jason Paschal wrote:
make ur submit button a regular button with an onClick event trigger:
<input name="button" type="button" id="button" onClick='validate()' value="Submit">
then make ur javascript submit the form if conditions are true. otherwise it gives an alert:
<script language="JavaScript"> function validate() { if (document.getElementById('ed2').checked) { document.getElementById('myform').submit(); } else { alert("check something."); } } </script>
---------------------------------------
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: "Jason Paschal" <[EMAIL PROTECTED]> Subject: Re: [PHP] Validating Dynamic Checkboxes Date: Fri, 6 Aug 2004 23:27:29 -0600
We are very close. I now get the javascript alert when I don't check any of the checkboxes. However, as soon as I click the OK button in the alert, the results page is returned.
Albert Padley
On Aug 6, 2004, at 10:55 PM, Jason Paschal wrote:
i read the other guy's bit. he may be referring to how you identify the elements. and that could be related to the same validation trouble you're still having.
i've had to do similar stuff, but it wasn't exactly the same. however, i had to give a an id different from the name of the element.
<input type='checkbox' name='ed[2]' id='ed2'>
and in ur javascript:
if ($counter > 1) {
$jscondition .= " || document.getElementById('ed" . $id . "').checked";
} else {
$jscondition .= "document.getElementById('ed" . $id . "').checked";
---------------------------------------
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: Re: [PHP] Validating Dynamic Checkboxes Date: Fri, 6 Aug 2004 22:36:10 -0600
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
_________________________________________________________________
Check out Election 2004 for up-to-date election news, plus voter tools and more! http://special.msn.com/msn/election2004.armx
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar – get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
-- 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