Jump to content

IF SiteGallery == 1 THEN 'checked'


jarv

Recommended Posts

Hi,

 

my variable $SiteGallery currently equals 0 but it could equal 1

I would like to setup radio buttons to define weather it's a 0 or a 1 by writing an if statement similar to: IF SiteGallery == 1 THEN 'checked'

<label>Gallery On
 <input type="radio" name="SiteGallery" value="1" />
</label> 
<label>Gallery Off
   <input type="radio" name="SiteGallery" value="0" />
</label>

can anyone help?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/279384-if-sitegallery-1-then-checked/
Share on other sites

<label>Gallery On
<input type="radio" name="SiteGallery" value="1" <?php echo ($sitegallery == 1 ? 'checked="checked"' : ''); ?> />
</label>
<label>Gallery Off
<input type="radio" name="SiteGallery" value="1" <?php echo ($sitegallery == 0 ? 'checked="checked"' : ''); ?> />
</label>

Not sure what you want to do. Eminently do-able of course, but why do you want to do this thing:

IF SiteGallery == 1 THEN 'checked'

 

The button will be in a checked state if the value equals 1.

Are you saying you want to set the radio button checked/unchecked when you output the page? Then use that same logic to set a var to null or 'checked' and add that var to your input tag.

$on='';

$off='';

if ($SiteGallery == '1')

$on = 'checked';

else

$off = 'checked';

 

echo "<label>Gallery On

<input type='radio' name='SiteGallery' value='1' $on/>

</label>

<label>Gallery Off

<input type='radio' name='SiteGallery' value='0' $off />

</label>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.