Page 1 of 1

A silly problem with radio buton

Posted: Tue Jul 15, 2008 6:18 am
by jawedshamshedi
Hi to all

I got a very silly problem with radio button, In my site i have 3 radio button, in the edit personal profile section i gave use three options of contact, mail, phone letter, and these radio's are filled from database with the values he has choosen. In IE safari it is running well but in firefox , it creating problem. In firefox it is not allowing to change the radio button, here the code.



<tr>
<td width="37%" class="text12grey"><div align="left">Preferred contact method</div></td>
<td width="61%"><label>
<input type="radio" name="method" id="method1" value="mail" <?php if ($row[contact_method] == 'mail'){ ?> checked="checked" <?php }?>/>
<span class="style3"> Mail </span>
<input type="radio" name="method" id="method2" value="phone" <?php if ($row[contact_method] == 'phone'){ ?> checked="checked" <?php }?> />
<span class="style3">Phone</span>
<input type="radio" name="method" id="method3" value="post" <?php if ($row[contact_method] == 'post'){ ?> checked="checked" <?php }?> />
<span class="style3"> Post </span></label></td>
</tr>


And thanks in advance for any help..

Re: A silly problem with radio buton

Posted: Tue Jul 15, 2008 8:07 am
by Dynamis
jawedshamshedi wrote: <input type="radio" name="method" id="method1" value="mail" <?php if ($row[contact_method] == 'mail'){ ?> checked="checked" <?php }?>/>
<input type="radio" name="method" id="method2" value="phone" <?php if ($row[contact_method] == 'phone'){ ?> checked="checked" <?php }?> />
<input type="radio" name="method" id="method3" value="post" <?php if ($row[contact_method] == 'post'){ ?> checked="checked" <?php }?> />
In your code, the checked="checked" is not within the php tag, so it is ALWAYS printed, even if $row[contact_method] is not equal to mail, phone, or post. The correct code should be...

Code: Select all

<input  type="radio"  name="method" id="method1" value="mail" <?php if ($row[contact_method] == 'mail') echo "checked"; ?>>
<input type="radio" name="method" id="method2" value="phone" <?php if ($row[contact_method] == 'phone') echo "checked"; ?>>
<input type="radio" name="method" id="method3" value="post" <?php if ($row[contact_method] == 'post') echo "checked"; ?>>

Re: A silly problem with radio buton

Posted: Wed Jul 16, 2008 6:24 am
by jawedshamshedi
hi all

thanks for the reply but wat u said about the checked thing, i dont thing it is write as when we have to repeat a tr in while loop then if the loop is not true then the tr is not shown.

but thanks for the reply, I found the error , but cant figure it out why this is happening

I putted the code of radio button in a label tag, when i omitted the tag the code is running as it was desired..

Thanks to all..