A silly problem with radio buton

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jawedshamshedi
Forum Commoner
Posts: 35
Joined: Fri May 16, 2008 1:17 am
Location: India
Contact:

A silly problem with radio buton

Post 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..
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: A silly problem with radio buton

Post 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"; ?>>
jawedshamshedi
Forum Commoner
Posts: 35
Joined: Fri May 16, 2008 1:17 am
Location: India
Contact:

Re: A silly problem with radio buton

Post 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..
Post Reply