[FX.php List] Adding a Radio Button set to an Array

Dale Bengston dbengston at preservationstudio.com
Thu Aug 30 08:20:18 MDT 2007


Hi William,

By nature, radio buttons only allow one to be selected. For multiple  
selections, checkboxes are appropriate. So you need to walk your  
array and create an input for each option in your array, and give  
each input the same name. Assuming a simple array...

$esNameSales = array(12345 => 'Klaus Beaudelaire', 23456 =>  
'Josephine Antwhistle', 34567 => 'Montgomery Montgomery');

...then this PHP code...

foreach ($esNameSales as $key => $value)
	{
	echo '<input type="radio" name="submit" value="' . $value . '">' .  
$value . '<br>';
	}

...would produce this html...

<input type="radio" name="submit" value="Klaus Beaudelaire">Klaus  
Beaudelaire
<input type="radio" name="submit" value="Josephine  
Antwhistle">Josephine Antwhistle
<input type="radio" name="submit" value="Montgomery  
Montgomery">Montgomery Montgomery

If your array is more complex, you might have to dig deeper to get  
the values out.

I hope this helps,
Dale


On Aug 30, 2007, at 6:15 AM, William Downs wrote:

> Hi guys,
>
> I need to add a radio button set to an array - the array is a returned
> set from an FX query (name, ID etc) - only the name is displayed to
> the user
>
> Of course, I would want to be able to select ONLY one radio.
>
> Just adding "<input type="radio" name="submit" value="<?php echo
> $esNameSales;?>">" does not make this a set where only one value is
> selectable
>
> I though of merging 2 arrays, but that seems overly complicated -
> anyone got an idea ?
>
> Much thanks in advance
>
> William
>
> -- 
> William Downs
> Development and Support
> BD Databases Ltd
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



More information about the FX.php_List mailing list