[liphp] problem populating radio button fields

Sean McCorkle [email protected]
Mon, 23 Jun 2003 13:29:12 -0400


 Veena - you're getting into trouble with this mixed-php-html code

<?if($proposal_data[7]=="MAD")?>checked="checked"

 Let me guess that checked="checked" is always coming out in the HTML

 I think the best way to write this is

  <? if($proposal_data[7]=="MAD") print( "checked=\"checked\" ); ?>

 Maybe its clunker, but its more explicit and I argue therefore that its
 easier to understand.

 I am well aware that PHP lets you embed pure html output streaming 
 in the code and that this is convenient sometimes, especially for large
 chunks of HTML output, but in your case, as the "THEN" clause of an "IF"
 statement, PHP needs to somehow know where the "THEN" clause ends.

 One way to do this is to enclose the "streamed html" in braces

 <?if($proposal_data[7]=="MAD") { ?>checked="checked" <? } ?>

=sean 

On Mon, Jun 23, 2003 at 01:07:28PM -0400, Venkatagiriyappa, Veena wrote:
> Hi,
> I have few fields which are of type "radio button" in my html form. I need
> to populate those with the values from database. But, with the below code
> it;s not doing correctly. 
> 
> [code]
> <td>Experiment type:</td>
>         <td>
>                 <input type="radio" name="expt" value="MAD"
> <?if($proposal_data[7]=="MAD")?>checked="checked">MAD
>                 <input type="radio" name="expt"
> value="SAD"<?if($proposal_data[7]=="SAD")?>checked="checked">SAD
>                 <input type="radio" name="expt" value="Single Wavelength"
> <?if($proposal_data[7]=="Single Wavelength")?>checked="checked">Single
> Wavelength </td>
> [/code]
> 
> $proposal_data[7] contains the value from the database. If I print it
> seperately, it's giving me the correct value which is 'Yes' or 'No'
> But in the form, the last field in this case 'Single Wavelength' is checked
> by default which is incorrect in some cases(depending on the row retreived
> from the database).
> I would appreciate if someone can figure out the possible problem in  the
> above method.
> 
> -Veena
> _______________________________________________
> Liphp mailing list
> [email protected]
> https://www.liphp.org/mailman/listinfo/liphp
-------------------------------------------------------------------------------
Sean R. McCorkle           [email protected]   | Haven't you heard, that aside
Genome Groupph  | from the details, there's
Biology Departmentfax | nothing further to be found?
Brookhaven National Laboratory                |    --Master Dogen's 300 Koan
Upton, New York  11973                        |      Shobogenzo  (commentary)