ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Radio button to determine output

May 07, 2011 11:58am

Subscribe [3]
  • #1 / May 07, 2011 11:58am

    Alex420

    18 posts

    Hello,

    I’m sure this is a really easy question to answer but I can’t seem to find much about it in the docs. What I would like to do is output different parts of a channel entry depending on whether or not a radio button is checked yes or no.

    I have set up a radio button custom field in my channel, called it {extra_info} and have then given it 2 values, yes and no. What I would now like to do is in my template put in an if statement that basically says: if the {extra_info} radio button has yes checked display this portion of code otherwise display another portion of code.

    I know this is a fairly straightforward if else statement but I can’t figure out how the syntax would work.

    Thanks in advance for any help and let me know if you need any more info.

  • #2 / May 07, 2011 12:52pm

    Mark Bowen

    12637 posts

    Hi Alex,

    I must admit I’ve not actually ever used a radio button before (I’m guessing you are referring to the built in ExpressionEngine custom field here) but the syntax should be something like this :

    {if extra_info == "yes"}
    …place code if button is checked as yes here…
    {if:else}
    …place code if button is checked as no here…
    {/if}

    Or you should be able to have two different checks if you need them for any reason :

    {if extra_info == "yes"}
    …code for yes…
    {/if}
    
    {if extra_info == "no"}
    …code for no…
    {/if}

    Be careful to use the same upper-case or lower-case versions of the word in both your conditional and the radio button setting. Always a good thing to do just in case it takes that into consideration when it performs its check.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / May 07, 2011 2:12pm

    Alex420

    18 posts

    Hey Mark,

    Thanks so much for getting back to me. I’ve given your suggestion a go but still don’t seem to be having much luck. At the moment none of the code in the if statement is being passed through no matter if the radio button has yes or no selected. Do I need to mention anything about the value of {extra_info} being set to yes or no in the if statement do you think?

    Kind regards,

    Alex

  • #4 / May 07, 2011 2:18pm

    Alex420

    18 posts

    Hi Mark,

    Forget that previous post of mine, I was being an idiot and forgot to change something in my mark up. Your suggestion works perfectly 😊

    Thanks again for your help on this, much appreciated!

    Best regards,

    Alex

  • #5 / May 07, 2011 7:58pm

    Mark Bowen

    12637 posts

    Hi Alex,

    Glad that got it working for you.

    Hope everything else goes well for you.

    Best wishes,

    Mark

  • #6 / May 08, 2011 11:18am

    Sue Crocker

    26054 posts

    Thanks for the assist, Mark.

    Alex420 - Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases