jarv Posted June 20, 2013 Share Posted June 20, 2013 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 Quote Link to comment Share on other sites More sharing options...
trq Posted June 20, 2013 Share Posted June 20, 2013 <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> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 20, 2013 Share Posted June 20, 2013 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>"; Quote Link to comment Share on other sites More sharing options...
jarv Posted June 20, 2013 Author Share Posted June 20, 2013 Thanks TRQ, that worked! thanks also to: ginerjm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.