| 
	
 | 
 Posted by Jerry Stuckle on 02/23/07 21:15 
Geoff Berrow wrote: 
> Message-ID: <CMydnX5KLv-Fe0PYnZ2dnUVZ_rSjnZ2d@comcast.com> from Jerry 
> Stuckle contained the following: 
>  
>> But again, JS "enhances the  
>> experience". 
>  
> It's funny how threads pop up when you have just been working on 
> something. 
>  
> I had an admin form with a list of records in text fields for editing. 
> My client wanted the choice of editing or deleting individual records so 
> I added a checkbox with  name=' chosen[]' value='$id' and so on.  Press 
> one button and the selected records would be updated, press another and 
> the chosen records get sent to a delete script. 
>  
> Then I had the bright idea that the checkbox should be checked if the 
> text was edited to 'enhance the experience' using an onChange event. 
> Ok, to do that each check box would have to have a different name so I 
> did 
> name=' chosen[$id]' value='$id'  
>  
> After much head scratching and cursing of JavaScript I discovered that 
> while php is happy with square brackets, Javascript isn't.  I eventually 
> had to name it name=' chosen$id' value='$id'  
>  
> But that meant I would no longer have my array of ids. :-( 
>  
> So I did this: 
>  
> foreach ($_POST as $key=>$value){ 
> 	if(substr($key,0,6)=='chosen'){ 
> 	$change[]=$value; 
> 	} 
> } 
>  
> Hope this helps someone stop scratching their head as much as I did. 
>  
 
Hi, Geoff, 
 
An even easier way: 
 
   name=' chosen[$id]' value='$id' id='chosen{$id} 
 
And in your Javascript use: 
 
   document.getElementById(chosen{$id}) 
 
That way both Javascript and PHP are happy. 
 
--  
================== 
Remove the "x" from my email address 
Jerry Stuckle 
JDS Computer Training Corp. 
jstucklex@attglobal.net 
==================
 
  
Navigation:
[Reply to this message] 
 |