Hi there everyone,
I have a form with check boxes and with PHP I use the array feature for the
form name.  Now I need to check if the tickboxes are ticked and if not
return an error, normally with javascript I would use:
<script language="JavaScript">
function validate_form ( )
{  valid = true;
    if ( document.removeitems.del.value == "" ){
       alert ( "You cannot remove an item if it is not selected." );
       valid = false;  }
   return valid; }

BUT because the tickboxes information is stored in a PHP Array called del[]
I am having major problems getting it to work.  Does anyone know how to
determine with javascript if any boxes are ticked, when the name for the box
is an Array such as del[] ???  I’m grabbing the data from my MySQL DB
without a hitch etc …. And I know technically this is more MySQL / PHP list,
but it is related and I’ve looked online and can’t seem to find anything, so
thought I’d try here as usually you are all very helpful.

Thank you


Hey Chris

So, PHP creates HTML and Javascript on the server end. Javascript is read in the browser. By the time the Javascript gets to do checks to see whether a box is pressed or not, the PHP array is long-gone.

You should run your PHP, and then check the source code it makes in the browser. What you'll hopefully see is a bunch of form boxes with the names they got from the array. So, use Javascript to check those names.

If your list is dynamic, so there might be del1, del2, del3, etc., you'll want to use a loop in Javascript to run through the names. To find out how many there are for the loop, PHP can dump a javascript variable called loopAmount or something.



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

Reply via email to