Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > how to check a radio button

Reply
Thread Tools

how to check a radio button

 
 
juicy
Guest
Posts: n/a
 
      03-27-2006
By default, I create several radio button and one of it checked="checked".
Now I would like to do some checking condition, and check the radio button
when condition match.

<?php if($c = 1){ ?>
<!-- check first radio button -->
<? else ?>
<!-- check second radio button -->
<? } ?>

Please give some idea or useful links. Thanks.

 
Reply With Quote
 
 
 
 
Mark Parnell
Guest
Posts: n/a
 
      03-27-2006
Deciding to do something for the good of humanity, juicy
<> declared in alt.html:

> <?php if($c = 1){ ?>


Will always return true. I think you mean <?php if($c == 1){ ?>.
http://www.php.net/manual/en/languag...comparison.php

> Please give some idea or useful links. Thanks.


<?php if($c == 1) { ?>
<input type="radio" checked="checked" value="1" name="c">
<input type="radio" value="2" name="c">
<? } else { ?>
<input type="radio" value="1" name="c">
<input type="radio" checked="checked" value="2" name="c">
<? } ?>

Perhaps not the most elegant solution, but it works. Gets messier the
more radio buttons you have. If it's only 2 like your example, then the
above will suffice.

--
Mark Parnell
Thankyou blinkynet!
http://blinkynet.net/comp/uip5.html
 
Reply With Quote
 
 
 
 
Bob Long
Guest
Posts: n/a
 
      03-27-2006
In news:,
Mark Parnell <> typed:
> Deciding to do something for the good of humanity, juicy
> <> declared in alt.html:
>
> > <?php if($c = 1){ ?>

>
> Will always return true. I think you mean <?php if($c == 1){ ?>.
> http://www.php.net/manual/en/languag...comparison.php
>
> > Please give some idea or useful links. Thanks.

>
> <?php if($c == 1) { ?>
> <input type="radio" checked="checked" value="1" name="c">
> <input type="radio" value="2" name="c">
> <? } else { ?>
> <input type="radio" value="1" name="c">
> <input type="radio" checked="checked" value="2" name="c">
> <? } ?>


Is it 'checked="checked"'? Or simply 'checked'? As in:

<input type="radio" checked value="2" name="c">

--
Bob Long


 
Reply With Quote
 
Mark Parnell
Guest
Posts: n/a
 
      03-27-2006
Deciding to do something for the good of humanity, Bob Long
<> declared in alt.html:

> Is it 'checked="checked"'? Or simply 'checked'?


Either is valid in HTML; only the first is in XHTML. IIRC some browsers
don't cope well with the short version either.

--
Mark Parnell
Thankyou blinkynet!
http://blinkynet.net/comp/uip5.html
 
Reply With Quote
 
yomna_fahmy yomna_fahmy is offline
Junior Member
Join Date: Jun 2011
Posts: 1
 
      06-27-2011
Hi juicy,

you can add the word checked by the condition, like this...

<input type="radio" name="color" value="1"
<? if($c==1) echo 'CHECKED';?> >

but careful because Checkboxes are off by default, but there is no default for which radio button is on when the form loads; most browsers have none on, some put the first one on.

Hope this helps
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Reset Radio Button in a group of Radio Buttons Scott D Johnson ASP .Net 1 09-27-2006 10:38 PM
Q: check radio button =?Utf-8?B?SklNLkgu?= ASP .Net 5 05-17-2005 03:58 PM
proper way to check radio button value? Flip ASP .Net 3 11-18-2004 03:13 PM
set ReadOnly to radio button and check box Grey ASP .Net 1 05-31-2004 10:00 AM
Radio button List problem: How to find value of Radio button list's Selected Item using javascript?? Hiten ASP .Net Web Controls 1 05-26-2004 10:32 AM



Advertisments