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
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>
Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.